-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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 12 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 |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
Period, | ||
Tick, | ||
Timestamp, | ||
offsets, | ||
to_offset, | ||
) | ||
from pandas._typing import ( | ||
|
@@ -9070,7 +9071,15 @@ def first(self, offset) -> Self: | |
if len(self.index) == 0: | ||
return self.copy(deep=False) | ||
|
||
if isinstance(offset, offsets.DateOffset): | ||
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. doesn't the 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 issue is that doing this check after 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. they need to be handled differently because something like |
||
end_date = end = self.index[0] + offset | ||
if end_date in self.index: | ||
end = self.index.searchsorted(end_date, side="left") | ||
return self.iloc[:end] | ||
return self.loc[:end] | ||
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. a lot of this looks really similar to what we have below. can any of this be de-duplicated? 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. Done |
||
|
||
offset = to_offset(offset) | ||
|
||
if not isinstance(offset, Tick) and offset.is_on_offset(self.index[0]): | ||
# GH#29623 if first value is end of period, remove offset with n = 1 | ||
# before adding the real offset | ||
|
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.
there is no pd.first. Maybe
:meth:DataFrame.first
?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.
Change done