-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
move shift_months to liboffsets, unify implementations of Q/M/Y offsets, #18375
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
move shift_months to liboffsets, unify implementations of Q/M/Y offsets, #18375
Conversation
algebra unification
…libs-offsets-shift_months
@@ -19,6 +21,10 @@ from pandas._libs.tslib import monthrange | |||
|
|||
from conversion cimport tz_convert_single, pydt_to_i8 | |||
from frequencies cimport get_freq_code | |||
from nattype cimport NPY_NAT |
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.
add these in setup.py
pandas/_libs/tslibs/offsets.pyx
Outdated
return days_per_month_table[is_leapyear(year)][month - 1] | ||
|
||
|
||
cdef inline int _year_add_months(pandas_datetimestruct dts, int months) nogil: |
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 de-privatize
Codecov Report
@@ Coverage Diff @@
## master #18375 +/- ##
==========================================
- Coverage 91.38% 91.32% -0.07%
==========================================
Files 164 164
Lines 49797 49703 -94
==========================================
- Hits 45508 45391 -117
- Misses 4289 4312 +23
Continue to review full report at Codecov.
|
@@ -577,7 +577,10 @@ def pxd(name): | |||
'pyxfile': '_libs/tslibs/offsets', | |||
'pxdfiles': ['_libs/src/util', | |||
'_libs/tslibs/conversion', | |||
'_libs/tslibs/frequencies']}, | |||
'_libs/tslibs/frequencies', |
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 future prs can reduce the tslib.pyx deps I think now that lots of things are moved out.
def shift_months(int64_t[:] dtindex, int months, object day=None): | ||
""" | ||
Given an int64-based datetime index, shift all elements | ||
specified number of months using DateOffset semantics |
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 doc-string things as well (here just fix the formatting to numpydoc)
This moves
tslib.shift_months
to liboffsets.After several algebra-simplifing PRs, here's the payoff. Nearly all of the logic in M/Q/Y offset subclasses is now identical, so can be moved into the parent classes.
BusinessMonthEnd
gains anonOffset
method (instead of inheriting fromDateOffset
)The Year and Day algebra is simple enough that the diff should be obvious. The
QuarterFoo.apply
methods are require a few steps of simplification before they become identical. I decided just to push the whole thing rather than drag it out.