-
-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0ed276f
BUG first
DeaMariaLeon 16028ed
Merge remote-tracking branch 'upstream/main' into newbug
DeaMariaLeon d76aa11
BUG first
DeaMariaLeon 1fee537
Merge remote-tracking branch 'upstream/main' into newbug
DeaMariaLeon fbf2d10
BUG fixing func first with DO
DeaMariaLeon 9d769b4
Merge remote-tracking branch 'upstream/main' into newbug
DeaMariaLeon bc4423a
Merge remote-tracking branch 'upstream/main' into newbug
DeaMariaLeon 45e594f
Modified as suggestions
DeaMariaLeon 643822c
Merge remote-tracking branch 'upstream/main' into newbug
DeaMariaLeon 5a6f4c7
Merge remote-tracking branch 'upstream/main' into newbug
DeaMariaLeon 0d80894
Corrected whatsnew
DeaMariaLeon dfc981d
Merge remote-tracking branch 'upstream/main' into newbug
DeaMariaLeon 621c028
fixing first
DeaMariaLeon 4d37542
added var
DeaMariaLeon ac12fdc
removed parenthesis
DeaMariaLeon 27b6377
Removed duplicated code
DeaMariaLeon 7bf43e6
Merge remote-tracking branch 'upstream/main' into newbug
DeaMariaLeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
Period, | ||
Tick, | ||
Timestamp, | ||
offsets, | ||
to_offset, | ||
) | ||
from pandas._typing import ( | ||
|
@@ -9091,16 +9092,25 @@ def first(self, offset) -> Self: | |
if len(self.index) == 0: | ||
return self.copy(deep=False) | ||
|
||
offset = to_offset(offset) | ||
if not isinstance(offset, Tick) and offset.is_on_offset(self.index[0]): | ||
if isinstance(offset, offsets.DateOffset): | ||
input_is_offset = True | ||
else: | ||
input_is_offset = False | ||
offset = to_offset(offset) | ||
|
||
if ( | ||
not isinstance(offset, Tick) | ||
and offset.is_on_offset(self.index[0]) | ||
and not input_is_offset | ||
): | ||
# 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 | ||
else: | ||
end_date = end = self.index[0] + offset | ||
|
||
# Tick-like, e.g. 3 weeks | ||
if isinstance(offset, Tick) and end_date in self.index: | ||
if isinstance(offset, Tick) or input_is_offset and end_date in self.index: | ||
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 can never remember if 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'll change that. |
||
end = self.index.searchsorted(end_date, side="left") | ||
return self.iloc[:end] | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
doesn't the
offset = to_offset(offset)
below make this check unnecessary?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 issue is that doing this check after
to_offset
would make it impossible to distinguish betweenMonthEnd
, as that would also satisfyisinstance(offset, DateOffset)
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.
they need to be handled differently because something like
DateOffset(days=15)
would always returnTrue
forif not isinstance(offset, Tick) and offset.is_on_offset(self.index[0])
, and so would be shifted backward byoffset.base
(this is why in the linked issues, the result only has a single row forDateOffset
input)