Skip to content

Commit c6c2fad

Browse files
committed
BUG: Fix dt64[non_nano] + offset rounding
1 parent 4f2dced commit c6c2fad

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

pandas/core/arrays/datetimes.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -825,14 +825,17 @@ def _add_offset(self, offset: BaseOffset) -> Self:
825825
"s",
826826
]
827827
res_unit = self.unit
828-
if hasattr(offset, "offset") and offset.offset is not None:
829-
if not isinstance(offset, TSeriesDateOffset):
830-
offset_td = Timedelta(offset.offset)
831-
if offset_td.value != 0:
832-
offset_unit = offset_td.unit
833-
idx_self = units.index(self.unit)
834-
idx_offset = units.index(offset_unit)
835-
res_unit = units[min(idx_self, idx_offset)]
828+
if isinstance(offset, TSeriesDateOffset):
829+
micro = offset.kwds.get("microseconds", 0)
830+
if micro and self.unit != "ns":
831+
res_unit = "us"
832+
elif hasattr(offset, "offset") and offset.offset is not None:
833+
offset_td = Timedelta(offset.offset)
834+
if offset_td.value != 0:
835+
offset_unit = offset_td.unit
836+
idx_self = units.index(self.unit)
837+
idx_offset = units.index(offset_unit)
838+
res_unit = units[min(idx_self, idx_offset)]
836839
result = type(self)._simple_new(res_values, dtype=res_values.dtype)
837840
result = result.as_unit(res_unit)
838841

0 commit comments

Comments
 (0)