-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
Fix offset __inits__, apply_index dtypes #19142
Conversation
…days add timedelta64[ns] array instead of int64 array
Travis looks like a moto problem. |
pandas/tseries/offsets.py
Outdated
@@ -1226,7 +1225,8 @@ def _get_roll(self, i, before_day_of_month, after_day_of_month): | |||
return roll | |||
|
|||
def _apply_index_days(self, i, roll): | |||
i += (roll % 2) * Timedelta(days=self.day_of_month).value | |||
nanos = (roll % 2) * Timedelta(days=self.day_of_month).value |
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 would rather
n = Timedelta((roll % 2) * Timedelta(days=self.day_of_month).value)
return i + n + Timedelta(days-1)
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.
roll
is an array
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.
then pls add a doc-string (same below)
pandas/tseries/offsets.py
Outdated
@@ -1271,13 +1271,14 @@ def _get_roll(self, i, before_day_of_month, after_day_of_month): | |||
return roll | |||
|
|||
def _apply_index_days(self, i, roll): | |||
return i + (roll % 2) * Timedelta(days=self.day_of_month - 1).value | |||
nanos = (roll % 2) * Timedelta(days=self.day_of_month - 1).value |
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.
same
@@ -1394,7 +1411,7 @@ class WeekOfMonth(_WeekOfMonthMixin, DateOffset): | |||
_prefix = 'WOM' | |||
_adjust_dst = True | |||
|
|||
def __init__(self, n=1, normalize=False, week=None, weekday=None): |
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.
this doesn't break anything???
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.
The default kwargs raise ATM.
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.
where is the test for this? why isn't it raising currently?
Codecov Report
@@ Coverage Diff @@
## master #19142 +/- ##
=========================================
Coverage ? 91.52%
=========================================
Files ? 147
Lines ? 48785
Branches ? 0
=========================================
Hits ? 44651
Misses ? 4134
Partials ? 0
Continue to review full report at Codecov.
|
pandas/tseries/offsets.py
Outdated
@@ -1226,7 +1225,8 @@ def _get_roll(self, i, before_day_of_month, after_day_of_month): | |||
return roll | |||
|
|||
def _apply_index_days(self, i, roll): | |||
i += (roll % 2) * Timedelta(days=self.day_of_month).value | |||
nanos = (roll % 2) * Timedelta(days=self.day_of_month).value |
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.
then pls add a doc-string (same below)
@@ -1394,7 +1411,7 @@ class WeekOfMonth(_WeekOfMonthMixin, DateOffset): | |||
_prefix = 'WOM' | |||
_adjust_dst = True | |||
|
|||
def __init__(self, n=1, normalize=False, week=None, weekday=None): |
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.
where is the test for this? why isn't it raising currently?
pandas/tseries/offsets.py
Outdated
return self._end_apply_index(i) | ||
|
||
def _end_apply_index(self, dtindex): | ||
"""Offsets index to end of Period frequency""" |
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.
doc-string
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.
Will do.
Until a few dozen PRs ago all that was passed to |
ok can you add some pls. |
since |
ping |
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -474,3 +474,4 @@ Other | |||
|
|||
- Improved error message when attempting to use a Python keyword as an identifier in a ``numexpr`` backed query (:issue:`18221`) | |||
- :func:`Timestamp.replace` will now handle Daylight Savings transitions gracefully (:issue:`18319`) | |||
- Bug in :class:`WeekOfMonth` and :class:`LastWeekOfMonth` where default keyword arguments for constructor raised ``ValueError`` (:issue:`19142`) |
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.
pls move this and the one above to COnversion, don't put things Other unless they obviously don't fit elsewhere. You could make a TimesSeries section if you want (and move appropriate things), but move this for now.
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. For future reference, what heuristic should I be using that maps WeekOfMonth.__init__ ValueError
to "conversion"?
thanks! |
This PR does two main things:
Change the default kwargs for offset
__init__
methods so that the defaults are valid; ATMWeekOfMonth()
andLastWeekOfMonth()
will both raiseValueError
.ATM
Week.apply_index
adds an int64 array to aDatetimeIndex
. This happens to have the desired output because the int64 array represents nanoseconds. This explicitly casts the array totimedelta64[ns]
to make this explicit. This is a necessary step towards fixing DatetimeIndex + ndarray[int] wrong, reverse op errors #19123.In addition there are two small pieces of refactoring:
Remove
liboffsets.EndMixin
since it is only mixed in toWeek
.Use
liboffsets.roll_convention
to de-duplicate some code inliboffsets.shift_months
.git diff upstream/master -u -- "*.py" | flake8 --diff