-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG fixing module first() and DateOffset #52487
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
0ed276f
16028ed
d76aa11
1fee537
fbf2d10
9d769b4
bc4423a
45e594f
643822c
5a6f4c7
0d80894
dfc981d
621c028
4d37542
ac12fdc
27b6377
7bf43e6
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 |
---|---|---|
|
@@ -40,7 +40,9 @@ | |
from pandas._libs.tslibs import ( | ||
Period, | ||
Tick, | ||
Timedelta, | ||
Timestamp, | ||
offsets, | ||
to_offset, | ||
) | ||
from pandas._typing import ( | ||
|
@@ -9076,9 +9078,20 @@ def first(self, offset) -> Self: | |
|
||
if len(self.index) == 0: | ||
return self.copy(deep=False) | ||
if type(offset) is not offsets.DateOffset: | ||
offset = to_offset(offset) | ||
|
||
offset = to_offset(offset) | ||
if not isinstance(offset, Tick) and offset.is_on_offset(self.index[0]): | ||
if type(offset) is offsets.DateOffset and offset.is_on_offset(self.index[0]): | ||
end_date = self.index[0] - Timedelta(1, unit="d") + offset | ||
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. I don't think we can hard-code (Pdb) p self.index[0]
Timestamp('2018-04-09 00:00:00')
(Pdb) p self.index[0] - Timedelta(1, unit='d')
Timestamp('2018-04-08 00:00:00')
(Pdb) p self.index[0] - Timedelta(1, unit='d') + offset
Timestamp('2018-04-08 00:02:00') 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. Thank you for the review! Some of the issues of DateOffset:
|
||
|
||
return self.loc[:end_date] | ||
|
||
# if not isinstance(offset, Tick) and offset.is_on_offset(self.index[0]): | ||
if ( | ||
not isinstance(offset, Tick) | ||
and offset.is_on_offset(self.index[0]) | ||
and type(offset) is not offsets.DateOffset | ||
): | ||
# GH#29623 if first value is end of period, remove offset with n = 1 | ||
# before adding the real offset | ||
end_date = end = self.index[0] - offset.base + offset | ||
|
Uh oh!
There was an error while loading. Please reload this page.