Skip to content

BUG: pandas.DataFrame.last doesn't respect time zone #52131 #52770

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
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9145,9 +9145,19 @@ def last(self, offset) -> Self:

offset = to_offset(offset)

start_date = self.index[-1] - offset
start = self.index.searchsorted(start_date, side="right")
return self.iloc[start:]
if not isinstance(offset, Tick) and offset.is_on_offset(self.index[-1]):
# GH#29623 if first value is end of period, remove offset with n = 1
# before adding the real offset
start_date = start = self.index[-1] - offset.base - offset
else:
start_date = start = self.index[-1] - offset

# Tick-like, e.g. 3 weeks
if isinstance(offset, Tick) and start_date in self.index:
start = self.index.searchsorted(start_date, side="right")
return self.iloc[:start]

return self.loc[:start]

@final
def rank(
Expand Down