-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fixed inconsistent offset behavior for series #43784 #48129
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
bab1995
c62dde3
ee8752f
ea1db06
e91a1d8
4179d58
c43f2be
d79646b
0fcf0fd
21ed3c4
ff0bd57
71ef3d2
b9a5479
7672f40
073b187
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 @@ | |
tz_convert_from_utc, | ||
tzconversion, | ||
) | ||
from pandas._libs.tslibs.offsets import DateOffset | ||
from pandas._typing import npt | ||
from pandas.errors import ( | ||
OutOfBoundsDatetime, | ||
|
@@ -694,7 +695,10 @@ def _add_offset(self, offset) -> DatetimeArray: | |
assert not isinstance(offset, Tick) | ||
|
||
if self.tz is not None: | ||
values = self.tz_localize(None) | ||
if not offset._use_relativedelta and type(offset) == DateOffset: | ||
values = self.tz_convert("utc").tz_localize(None) | ||
else: | ||
values = self.tz_localize(None) | ||
else: | ||
values = self | ||
|
||
|
@@ -716,7 +720,10 @@ def _add_offset(self, offset) -> DatetimeArray: | |
result = DatetimeArray._simple_new(result, dtype=result.dtype) | ||
if self.tz is not None: | ||
# FIXME: tz_localize with non-nano | ||
result = result.tz_localize(self.tz) | ||
if not offset._use_relativedelta and type(offset) == 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. So this only is needed for 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. Correct. Almost all of the subclasses of 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 this will be robust to users subclassing and defining their own 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 wasn't thinking about user-created subclasses in my original response, rather I was thinking of the predefined subclasses like |
||
result = result.tz_localize("utc").tz_convert(self.tz) | ||
else: | ||
result = result.tz_localize(self.tz) | ||
|
||
return result | ||
|
||
|
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.
Could you undo this reordering?