fix: dehumanize accepts singular nouns with numeric prefix ("1 day ago")#1322
Open
amitmishra11 wants to merge 1 commit into
Open
fix: dehumanize accepts singular nouns with numeric prefix ("1 day ago")#1322amitmishra11 wants to merge 1 commit into
amitmishra11 wants to merge 1 commit into
Conversation
'1 day ago', '1 week ago', '1 hour ago' etc. previously raised
ValueError because the primary search pattern for singular timeframes
(e.g. 'a day') never matched a numeric prefix. A fallback pattern
using the bare unit key (e.g. r'\d+\s+day\b') is now tried when the
singular form has no {0} placeholder, making numeric and article forms
interchangeable for all en-us singular units.
Fixes arrow-py#1150
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1322 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 2315 2318 +3
Branches 358 359 +1
=========================================
+ Hits 2315 2318 +3 ☔ View full report in Codecov by Harness. |
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.
Pull Request Checklist
masterbranch.Description of Changes
Closes #1150
dehumanizesilently rejected strings like"1 day ago"or"in 1 week"with aValueError, while the plural form"1 days ago"worked fine.Root cause
Singular timeframes in the locale have no
{0}placeholder (e.g."a day"for the"day"key). The search pattern built from that string is(^|\b|\d)a day, which never matches"1 day". No other pattern covers"1 day"either, sounit_visitedstays all-False and the function raises.Fix
When the primary pattern fails to match and the timeframe string has no
{0}placeholder, a fallback pattern is tried using the bare unit key itself:For English this catches
"1 day","1 week","1 hour","1 second"etc. For other locales the fallback either matches (if the unit key happens to appear in the input) or stays None — so existing behavior for non-English locales is unchanged.Summary
Changes
arrow/arrow.py: add numeric fallback for singular timeframes indehumanizetests/test_arrow.py: addtest_singular_with_numbercovering all seven en-us singular unitsTesting
Fixes #1150