-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
BUG: Fix dt64[non_nano] + some_offsets incorrectly rounding #62383
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
184ad31
0f088f5
f8e31d4
259a5e4
4436054
00ee4c8
e54c162
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 |
---|---|---|
|
@@ -64,6 +64,7 @@ | |
) | ||
from pandas.core.dtypes.missing import isna | ||
|
||
from pandas import Timedelta | ||
from pandas.core.arrays import datetimelike as dtl | ||
from pandas.core.arrays._ranges import generate_regular_range | ||
import pandas.core.common as com | ||
|
@@ -93,7 +94,6 @@ | |
|
||
from pandas import ( | ||
DataFrame, | ||
Timedelta, | ||
) | ||
from pandas.core.arrays import PeriodArray | ||
|
||
|
@@ -817,12 +817,34 @@ def _add_offset(self, offset: BaseOffset) -> Self: | |
result = type(self)._from_sequence(res_values, dtype=self.dtype) | ||
|
||
else: | ||
result = type(self)._simple_new(res_values, dtype=res_values.dtype) | ||
units = [ | ||
"ns", | ||
"us", | ||
"ms", | ||
"s", | ||
] | ||
res_unit = self.unit | ||
if hasattr(offset, "offset"): | ||
offset_td = Timedelta(offset.offset) | ||
offset_unit = offset_td.unit | ||
if self.unit in units and offset_unit in units: | ||
idx_self = units.index(self.unit) | ||
idx_offset = units.index(offset_unit) | ||
res_unit = units[min(idx_self, idx_offset)] | ||
dtype_naive = np.dtype(f"datetime64[{res_unit}]") | ||
|
||
if res_values.dtype != dtype_naive: | ||
res_values = res_values.astype(dtype_naive) | ||
result = type(self)._simple_new(res_values, dtype=dtype_naive) | ||
|
||
if offset.normalize: | ||
result = result.normalize() | ||
result._freq = None | ||
|
||
if self.tz is not None: | ||
if ( | ||
self.tz is not None | ||
and getattr(result.dtype, "tz", None) is None | ||
and res_unit == "ns" | ||
): | ||
|
||
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.
is there ever False?
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.
no
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.
Then the check is not necessary