Fix dehumanize not recognizing singular nouns like '1 day ago'#1244
Open
worksbyfriday wants to merge 1 commit intoarrow-py:masterfrom
Open
Fix dehumanize not recognizing singular nouns like '1 day ago'#1244worksbyfriday wants to merge 1 commit intoarrow-py:masterfrom
worksbyfriday wants to merge 1 commit intoarrow-py:masterfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1150.
arrow.now().dehumanize("1 day ago")raisesValueErrorbecause 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
EnglishLocalefrom plain strings toMappingdicts with both"singular"and"plural"forms:Added
_format_timeframeoverride toEnglishLocalethat selects the correct form based on delta (singular forabs(delta) == 1, plural otherwise). This keeps humanize output completely unchanged while allowing dehumanize to match both forms.Test plan
test_singular_nouns_englishcovering all time units with numeric "1" in both past and future tense