-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix offset __inits__, apply_index dtypes #19142
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
Changes from 4 commits
891374a
1b7d11a
cd08026
38415c4
0cf28ba
c851879
8bcf15c
11aa109
39e0090
baa07b1
4a1c28c
2a516e2
6658679
162504b
39b66b5
dbd40ef
4ea4e1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ | |
apply_index_wraps, | ||
roll_yearday, | ||
shift_month, | ||
EndMixin, | ||
BaseOffset) | ||
|
||
|
||
|
@@ -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 | ||
i += nanos.astype('timedelta64[ns]') | ||
return i + Timedelta(days=-1) | ||
|
||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
return i + nanos.astype('timedelta64[ns]') | ||
|
||
|
||
# --------------------------------------------------------------------- | ||
# Week-Based Offset Classes | ||
|
||
class Week(EndMixin, DateOffset): | ||
class Week(DateOffset): | ||
""" | ||
Weekly offset | ||
|
||
|
@@ -1327,6 +1328,22 @@ def apply_index(self, i): | |
else: | ||
return self._end_apply_index(i, self.freqstr) | ||
|
||
def _end_apply_index(self, dtindex, freq): | ||
"""Offsets index to end of Period frequency""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Will do. |
||
off = dtindex.to_perioddelta('D') | ||
|
||
base_period = dtindex.to_period('W') | ||
if self.n > 0: | ||
# when adding, dates on end roll to next | ||
normed = dtindex - off | ||
roll = np.where(base_period.to_timestamp(how='end') == normed, | ||
self.n, self.n - 1) | ||
else: | ||
roll = self.n | ||
|
||
base = (base_period + roll).to_timestamp(how='end') | ||
return base + off | ||
|
||
def onOffset(self, dt): | ||
if self.normalize and not _is_normalized(dt): | ||
return False | ||
|
@@ -1380,9 +1397,9 @@ class WeekOfMonth(_WeekOfMonthMixin, DateOffset): | |
Parameters | ||
---------- | ||
n : int | ||
week : {0, 1, 2, 3, ...}, default None | ||
week : {0, 1, 2, 3, ...}, default 0 | ||
0 is 1st week of month, 1 2nd week, etc. | ||
weekday : {0, 1, ..., 6}, default None | ||
weekday : {0, 1, ..., 6}, default 0 | ||
0: Mondays | ||
1: Tuesdays | ||
2: Wednesdays | ||
|
@@ -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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. where is the test for this? why isn't it raising currently? |
||
def __init__(self, n=1, normalize=False, week=0, weekday=0): | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.weekday = weekday | ||
|
@@ -1457,7 +1474,7 @@ class LastWeekOfMonth(_WeekOfMonthMixin, DateOffset): | |
Parameters | ||
---------- | ||
n : int, default 1 | ||
weekday : {0, 1, ..., 6}, default None | ||
weekday : {0, 1, ..., 6}, default 0 | ||
0: Mondays | ||
1: Tuesdays | ||
2: Wednesdays | ||
|
@@ -1470,7 +1487,7 @@ class LastWeekOfMonth(_WeekOfMonthMixin, DateOffset): | |
_prefix = 'LWOM' | ||
_adjust_dst = True | ||
|
||
def __init__(self, n=1, normalize=False, weekday=None): | ||
def __init__(self, n=1, normalize=False, weekday=0): | ||
self.n = self._validate_n(n) | ||
self.normalize = normalize | ||
self.weekday = weekday | ||
|
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
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 arrayThere 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)