-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Implement scalar shift_month mirroring tslib.shift_months #18218
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
Implement scalar shift_month mirroring tslib.shift_months #18218
Conversation
Hello @jbrockmendel! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on November 12, 2017 at 00:22 Hours UTC |
We would expect the Month, Quarter, Year (and Business/Custom) offsets to be affected by this:
|
@@ -252,6 +253,8 @@ def apply_index(self, i): | |||
"applied vectorized".format(kwd=kwd)) | |||
|
|||
def isAnchored(self): | |||
# TODO: Does this make sense for the general case? It would help | |||
# if there were a canonical docstring for what isAnchored means. |
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.
@jreback : Thoughts?
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.
yeah to be honested I am not sure isAnchored
is really necessary, but that's orthogonal
@@ -721,6 +724,7 @@ def apply(self, other): | |||
|
|||
return result | |||
else: | |||
# TODO: Figure out the end of this sente |
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 presume you're going to figure this out beforehand?
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 mean what the end of the error message should be? That's orthogonal to this PR, but merits a reminder.
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.
yeah not sure, @sinhrks wrote this originally.
this looks reasonable. pls add a whatsnew note on improved perf of offsets, add all PRs that touch offsets.pyx to this issue. |
@@ -252,6 +253,8 @@ def apply_index(self, i): | |||
"applied vectorized".format(kwd=kwd)) | |||
|
|||
def isAnchored(self): | |||
# TODO: Does this make sense for the general case? It would help | |||
# if there were a canonical docstring for what isAnchored means. |
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.
yeah to be honested I am not sure isAnchored
is really necessary, but that's orthogonal
@@ -721,6 +724,7 @@ def apply(self, other): | |||
|
|||
return result | |||
else: | |||
# TODO: Figure out the end of this sente |
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.
yeah not sure, @sinhrks wrote this originally.
pandas/_libs/tslibs/offsets.pyx
Outdated
@@ -15,7 +15,7 @@ np.import_array() | |||
|
|||
from util cimport is_string_object | |||
|
|||
from pandas._libs.tslib import pydt_to_i8 | |||
from pandas._libs.tslib import pydt_to_i8, monthrange |
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.
prob should move monthrange
and everything in its impl to offsets (and then you can cimport these to tslib.pyx)
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.
Eventually. We've got a few more of these left to go.
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.
k, add to the list
doesn't this supersede #18183 ? |
Will do. |
Yes. Just closed that one. |
pandas/_libs/tslibs/offsets.pyx
Outdated
int year, month, day | ||
int dim, dy | ||
|
||
(dy, month) = divmod(stamp.month + months, 12) |
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.
cython doesn't seem to optimize this, instead write the two ops directly
dy = (stamp.month + months) // 12
month = (stamp.month + months) % 12
Codecov Report
@@ Coverage Diff @@
## master #18218 +/- ##
==========================================
- Coverage 91.4% 91.38% -0.02%
==========================================
Files 163 163
Lines 50091 50091
==========================================
- Hits 45788 45778 -10
- Misses 4303 4313 +10
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.
rebase
doc/source/whatsnew/v0.22.0.txt
Outdated
@@ -70,7 +70,7 @@ Performance Improvements | |||
~~~~~~~~~~~~~~~~~~~~~~~~ | |||
|
|||
- Indexers on Series or DataFrame no longer create a reference cycle (:issue:`17956`) | |||
- | |||
- DateOffset arithmetic performance is improved (:issue:`18218`) |
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.
use a :class`DateOffset`
(its now defined
pandas/_libs/tslibs/offsets.pyx
Outdated
elif day_opt == 'end': | ||
day = dim | ||
else: | ||
# assume this is an integer (and a valid day) |
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.
? why is day_opt anything else?
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.
and if it is, then explicity put 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.
? why is day_opt anything else?
For e.g. semi-month offsets we may be shifting to a particular day other than the first or last of the month.
and if it is, then explicity put it.
You mean assert it? OK. I'll go ahead and write a docstring too.
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.
check if it’s an integer
the else clause should raise
…libs-offsets-shift_month
Clipboard. |
thanks! |
replace relativedelta usage in relevant cases.
This should be orthogonal to other ongoing offsets PRs.
Ran asv repeatedly overnight, posting results below.