Skip to content

Fix dehumanize not recognizing singular nouns like '1 day ago'#1244

Open
worksbyfriday wants to merge 1 commit intoarrow-py:masterfrom
worksbyfriday:fix-dehumanize-singular
Open

Fix dehumanize not recognizing singular nouns like '1 day ago'#1244
worksbyfriday wants to merge 1 commit intoarrow-py:masterfrom
worksbyfriday:fix-dehumanize-singular

Conversation

@worksbyfriday
Copy link

Summary

Fixes #1150.

arrow.now().dehumanize("1 day ago") raises ValueError because the English locale's plural timeframe entries only contain the plural form (e.g. "{0} days"), which can't match the singular noun "day". The singular entries ("day": "a day") only match the "a/an" form, not the numeric "1" form.

Changes

Changed the plural timeframe entries in EnglishLocale from plain strings to Mapping dicts with both "singular" and "plural" forms:

# Before
"days": "{0} days",

# After  
"days": {"singular": "{0} day", "plural": "{0} days"},

Added _format_timeframe override to EnglishLocale that selects the correct form based on delta (singular for abs(delta) == 1, plural otherwise). This keeps humanize output completely unchanged while allowing dehumanize to match both forms.

Test plan

  • Added test_singular_nouns_english covering all time units with numeric "1" in both past and future tense
  • Verified "a/an" forms still work
  • Verified plural forms still work
  • All 297 dehumanize + locale tests pass
  • All 51 humanize tests pass — output unchanged

The English locale's plural timeframes (seconds, minutes, hours, etc.)
only had a single format string (e.g. "{0} days"), so dehumanize could
match "2 days ago" but not "1 day ago". The singular entries (second,
minute, etc.) mapped to "a second", "a minute", etc. — matching "a day
ago" but not "1 day ago".

Changed the plural timeframe entries to Mapping dicts with both
"singular" ("{0} day") and "plural" ("{0} days") forms, and overrode
_format_timeframe to select the correct form based on delta. This
allows dehumanize to match both "1 day ago" and "2 days ago", while
keeping humanize output unchanged ("a day ago" for delta=1, "2 days
ago" for delta=2).

Fixes arrow-py#1150.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The dehumanize method doesn't recognize singular nouns

1 participant