-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Break utils.ambiuous_date_to_date_range
to new class
#532
Break utils.ambiuous_date_to_date_range
to new class
#532
Conversation
74599e4
to
72086e7
Compare
Codecov Report
@@ Coverage Diff @@
## master #532 +/- ##
==========================================
+ Coverage 20.91% 21.38% +0.46%
==========================================
Files 31 32 +1
Lines 5136 5159 +23
Branches 1302 1303 +1
==========================================
+ Hits 1074 1103 +29
+ Misses 4010 4004 -6
Partials 52 52
Continue to review full report at Codecov.
|
72086e7
to
b7bb8f0
Compare
👍 for rewriting this!
However, I'm not sure that this behaviour expansion is desirable. |
I agree with @tsibley on this! |
Makes sense. I'll continue the legacy behavior here and open a followup issue to discuss possible enhancement. |
Actually, I misread the legacy implementation when I wrote that note about expanding the functionality—Augur already behaves this way (except for a detail regarding the year). # on current master branch
from augur.utils import ambiguous_date_to_date_range
>>> ambiguous_date_to_date_range("2000-01-01", "%Y-%m-%d")
(datetime.date(2000, 1, 1), datetime.date(2000, 1, 1))
>>> ambiguous_date_to_date_range("2000-01-XX", "%Y-%m-%d")
(datetime.date(2000, 1, 1), datetime.date(2000, 1, 31))
>>> ambiguous_date_to_date_range("2000-XX-05", "%Y-%m-%d")
(datetime.date(2000, 1, 5), datetime.date(2000, 12, 5))
# when year is uncertain, it falls back to the final (optional) argument:
>>> ambiguous_date_to_date_range("20XX-03-05", "%Y-%m-%d")
(None, None)
>>> ambiguous_date_to_date_range("20XX-03-05", "%Y-%m-%d", min_max_year=(1992, 2003))
(datetime.date(1992, 3, 5), datetime.date(2003, 3, 5)) I suppose there are three paths forward:
|
@elebow Oh, weird. Nice digging! I would prefer (3) and would consider it a kind of bug fix, but (2) might be more called for so that we don't break compat. |
Thanks for this! I agree with @tsibley that behavior 3 is preferable. |
This slightly expands the function's capabilities: any "X" character anywhere in the string will be disambiguated, rather than just at the least significant positions.
augur.utils.ambiguous_date_to_date_range resolves ambiguous dates into tuples of the min and max possible dates. Uncertainty is conveyed by using the "X" character in the date pattern. But it usually only makes sense for uncertainty to be in the least-significant places. For example, assuming %Y-%m-%d, a pattern of 2000-XX-05 would mean the 5th day of any month in 2000. This is almost certainly erroneous data and undesired behavior. Therefore, DateDisambiguator now raises an error when a constrained digit appears in a less-significant place than an uncertain digit.
Ongoing refactoring efforts have been trying to introduce new packages. All packages must be listed in the packages argument to `setuptools.setup()`. `setuptools.find_packages()` provides a convenient way to list all packages without manually updating a list.
b7bb8f0
to
4f6f238
Compare
Added a check that raises a Also rebased on latest master. Note that this still includes the cherry-picked commit from #527. |
this looks good to me. @tsibley, do you have additional comments? |
LGTM! |
Description of proposed changes
Rewrite
utils.ambiguous_date_to_date_range
as a new class.This slightly expands the function's capabilities: any
X
character anywhere in the string will be disambiguated, rather than just at the least significant positions. It should be fully backwards-compatible.Related issue(s)
none
Testing
Unit tests included.