Skip to content

Commit 6342364

Browse files
authored
BUG: resample don't work with non-nanosecond reso (#50774)
* find failing test * another fixup * test_sample_size still failing * some more fixups * wip * test_sample_size still failing * some more fixups * parametrise over unit for more tests Co-authored-by: MarcoGorelli <>
1 parent 91c9419 commit 6342364

File tree

3 files changed

+303
-198
lines changed

3 files changed

+303
-198
lines changed

pandas/core/arrays/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ def tz_localize(
10311031

10321032
if self.tz is not None:
10331033
if tz is None:
1034-
new_dates = tz_convert_from_utc(self.asi8, self.tz)
1034+
new_dates = tz_convert_from_utc(self.asi8, self.tz, reso=self._creso)
10351035
else:
10361036
raise TypeError("Already tz-aware, use tz_convert to convert.")
10371037
else:

pandas/core/resample.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import copy
4-
from datetime import timedelta
54
from textwrap import dedent
65
from typing import (
76
TYPE_CHECKING,
@@ -90,7 +89,6 @@
9089
)
9190
from pandas.tseries.offsets import (
9291
Day,
93-
Nano,
9492
Tick,
9593
)
9694

@@ -1715,7 +1713,7 @@ def _get_time_bins(self, ax: DatetimeIndex):
17151713
name=ax.name,
17161714
ambiguous=True,
17171715
nonexistent="shift_forward",
1718-
)
1716+
).as_unit(ax.unit)
17191717

17201718
ax_values = ax.asi8
17211719
binner, bin_edges = self._adjust_bin_edges(binner, ax_values)
@@ -1751,7 +1749,11 @@ def _adjust_bin_edges(self, binner, ax_values):
17511749
if self.closed == "right":
17521750
# GH 21459, GH 9119: Adjust the bins relative to the wall time
17531751
bin_edges = binner.tz_localize(None)
1754-
bin_edges = bin_edges + timedelta(1) - Nano(1)
1752+
bin_edges = (
1753+
bin_edges
1754+
+ Timedelta(days=1, unit=bin_edges.unit).as_unit(bin_edges.unit)
1755+
- Timedelta(1, unit=bin_edges.unit).as_unit(bin_edges.unit)
1756+
)
17551757
bin_edges = bin_edges.tz_localize(binner.tz).asi8
17561758
else:
17571759
bin_edges = binner.asi8

0 commit comments

Comments
 (0)