-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Follow-Up: Unify apply and onOffset implementations #18329
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
Follow-Up: Unify apply and onOffset implementations #18329
Conversation
Codecov Report
@@ Coverage Diff @@
## master #18329 +/- ##
==========================================
- Coverage 91.38% 91.36% -0.02%
==========================================
Files 164 164
Lines 49780 49786 +6
==========================================
- Hits 45491 45488 -3
- Misses 4289 4298 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18329 +/- ##
==========================================
- Coverage 91.38% 91.34% -0.05%
==========================================
Files 164 164
Lines 49790 49796 +6
==========================================
- Hits 45501 45486 -15
- Misses 4289 4310 +21
Continue to review full report at Codecov.
|
pandas/_libs/tslibs/offsets.pyx
Outdated
@@ -394,6 +394,10 @@ class _BaseOffset(object): | |||
out = '<%s' % n_str + className + plural + self._repr_attrs() + '>' | |||
return out | |||
|
|||
def _get_offset_day(self, datetime other): | |||
# subclass must implement `_day_opt` |
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.
so in the Base class add a NotImplementedError for this
pandas/_libs/tslibs/offsets.pyx
Outdated
else: | ||
# Note: unlike `shift_month`, get_day_of_month does not |
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 a test with a sub-class of BaseOffset (e.g. a dummy class) that checks this
Appveyor error looks like floating point error in an unrelated test. Will push dummy commit in a bit. |
can you rebase |
…libs-offsets-followup
looks fine. can you run the offset asvs & report
is? |
Pretty tame by local standards:
|
One more:
|
thanks! |
@@ -357,6 +357,7 @@ class _BaseOffset(object): | |||
_typ = "dateoffset" | |||
_normalize_cache = True |
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.
in a followup (TODO), can you add a description of these attributes in the doc-string of this class. (e.g. what the options are, what they do, etc).
This follows up on #18280, #18278, and #18263.
get_day_of_month
is extended to handlebusiness_start
andbusiness_end
in addition tostart
andend
._day_opt
attributes are added to YearFoo, QuarterFoo, and MonthFoo offsets. After some more algebraic simplification (done in a separate PR), their apply and onOffset methods will become identical and can be implemented in the base Year, Quarter, and Month classes.I expect a small performance penalty from calling
self._get_offset_day
in cases where could hard-code1
, but the benefits of a unified+simplified implementation outweigh that.