Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
184ad31
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Sep 19, 2025
0f088f5
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Oct 4, 2025
f8e31d4
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Oct 16, 2025
259a5e4
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Oct 16, 2025
9c95525
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Oct 29, 2025
dcf4dfc
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Oct 29, 2025
4a4d976
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 11, 2025
ba029d1
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 13, 2025
e27110a
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 13, 2025
4f2dced
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 14, 2025
c6c2fad
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 14, 2025
00ad36c
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 21, 2025
87cbc42
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 22, 2025
e4b91c4
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 22, 2025
b6f945d
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 22, 2025
1b571f7
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 22, 2025
6722152
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 22, 2025
3f5af74
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 22, 2025
9372a88
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Nov 22, 2025
2730c89
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Dec 3, 2025
b5acd0b
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Dec 13, 2025
b4f28d5
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Dec 13, 2025
fff5bc5
Revert "BUG: Fix dt64[non_nano] + offset rounding"
Aniketsy Dec 13, 2025
5c89d8c
BUG: Fix dt64[non_nano] + offset rounding
Aniketsy Dec 13, 2025
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
24 changes: 23 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
NaT,
NaTType,
Resolution,
Timedelta,
Timestamp,
astype_overflowsafe,
fields,
Expand Down Expand Up @@ -70,6 +71,7 @@

from pandas.tseries.frequencies import get_period_alias
from pandas.tseries.offsets import (
DateOffset,
Day,
Tick,
)
Expand All @@ -93,7 +95,6 @@

from pandas import (
DataFrame,
Timedelta,
)
from pandas.core.arrays import PeriodArray

Expand Down Expand Up @@ -817,7 +818,28 @@ def _add_offset(self, offset: BaseOffset) -> Self:
result = type(self)._from_sequence(res_values, dtype=self.dtype)

else:
units = [
"ns",
"us",
"ms",
"s",
]
res_unit = self.unit
if type(offset) is DateOffset:
if "nanoseconds" in offset.kwds:
res_unit = "ns"
elif "microseconds" in offset.kwds and self.unit != "ns":
res_unit = "us"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side-note for another PR: might be worth defining a unit property on DateOffset since i think this recently came up in date_range too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. would it make sense to open an issue for it or would you prefer I handle it directly in a follow up PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is fine

if hasattr(offset, "offset") and offset.offset is not None:
offset_td = Timedelta(offset.offset)
if offset_td.value != 0:
offset_unit = offset_td.unit
idx_self = units.index(self.unit)
idx_offset = units.index(offset_unit)
res_unit = units[min(idx_self, idx_offset)]
result = type(self)._simple_new(res_values, dtype=res_values.dtype)
result = result.as_unit(res_unit)

if offset.normalize:
result = result.normalize()
result._freq = None
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,3 +844,23 @@ def test_factorize_sort_without_freq():
tda = dta - dta[0]
with pytest.raises(NotImplementedError, match=msg):
tda.factorize(sort=True)


@pytest.mark.filterwarnings(
"ignore:Non-vectorized DateOffset being applied to Series or DatetimeIndex"
)
def test_dt64_non_nano_offset_no_rounding():
# GH#56586
dti = pd.date_range("2016-01-01", periods=3, unit="s")
offset = pd.offsets.CustomBusinessDay(offset=pd.Timedelta("1ms"))
result = dti + offset

assert result.dtype == np.dtype("datetime64[ms]")
expected = pd.DatetimeIndex(
[
pd.Timestamp("2016-01-02 00:00:00.001"),
pd.Timestamp("2016-01-03 00:00:00.001"),
pd.Timestamp("2016-01-04 00:00:00.001"),
]
)
tm.assert_index_equal(result, expected)
Loading