-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
simplify+unify offset.apply logic #18263
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
simplify+unify offset.apply logic #18263
Conversation
Running asv now. |
The optimist in me thinks the time_dti_tz_factorize might be real, but for the most part this looks like a wash. |
|
These numbers are against an out-of-date master. Will update. update well maybe not that out of date. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comments. nice removing code! can you confirm that we have sufficient test coverage of things that you are changing (I think yes, but have a look)
pandas/_libs/tslibs/offsets.pyx
Outdated
|
||
If it's a saturday or sunday, increment first business day to reflect this | ||
|
||
days_in_month arg is a dummy so that this has the same signature as | ||
_get_lastbday. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can type these
pandas/_libs/tslibs/offsets.pyx
Outdated
@@ -416,15 +425,21 @@ cpdef datetime shift_month(datetime stamp, int months, object day_opt=None): | |||
dy -= 1 | |||
year = stamp.year + dy | |||
|
|||
dim = monthrange(year, month)[1] | |||
(wkday, days_in_month) = monthrange(year, month) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no parens
pandas/_libs/tslibs/offsets.pyx
Outdated
elif day_opt == 'start': | ||
day = 1 | ||
elif day_opt == 'end': | ||
day = dim | ||
day = days_in_month | ||
elif day_opt == 'bstart': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about business_start/end
pandas/tseries/offsets.py
Outdated
|
||
wkday, days_in_month = tslib.monthrange(other.year, other.month) | ||
lastBDay = days_in_month - max(((wkday + days_in_month - 1) | ||
% 7) - 4, 0) | ||
lastBDay = _get_lastbday(wkday, days_in_month) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok to de-privatize get_lastbday/first
Making edits per comments now. As to test coverage (here and in the other two similar PRs): as I went through these I added equality assertions for new vs old versions followed by |
…libs-offsets-paramd
Codecov Report
@@ Coverage Diff @@
## master #18263 +/- ##
===========================================
- Coverage 91.4% 39.44% -51.96%
===========================================
Files 164 164
Lines 49880 49857 -23
===========================================
- Hits 45592 19667 -25925
- Misses 4288 30190 +25902
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18263 +/- ##
==========================================
- Coverage 91.39% 91.36% -0.04%
==========================================
Files 164 164
Lines 49854 49781 -73
==========================================
- Hits 45566 45484 -82
- Misses 4288 4297 +9
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also can you unit test some these?
pandas/_libs/tslibs/offsets.pyx
Outdated
""" | ||
wkday is the result of monthrange(year, month) | ||
(wkday, days_in_month) is the result of monthrange(year, month) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you update doc-strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to reflect what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean update to a more proper doc-string
…libs-offsets-paramd
Yes, but since I just added a test_liboffsets file in #18280 I'd rather close these out separately and then add unit tests in a shared follow-up. |
@jbrockmendel general comment: can you try to use a bit more descriptive PR titles? "Tslibs offsets paramd" does not say much to me :-) |
You got it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add some unit tests
pandas/_libs/tslibs/offsets.pyx
Outdated
""" | ||
wkday is the result of monthrange(year, month) | ||
(wkday, days_in_month) is the result of monthrange(year, month) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean update to a more proper doc-string
Sure thing. |
pls hold off on this pending double-checking cross-DST behavior. |
OK, I've convinced myself the DST issue is handled. |
thanks, as always more tests are welcome! (w.r.t. DST) |
I'm psyched to have this merged. There's some follow-ups headed you're way I think you'll like. w/r/t DST Specifically w/r/t to DST tests I've been thinking of trying hypothesis (#17978) |
Implement _get_lastbday mirroring _get_firstbday.
Implement bstart and bend cases in shift month. Use these to simplify a bunch of the BusinessFoo offsets.