Skip to content

Commit d3995f7

Browse files
authored
BUG/ENH: infer_freq with non-nano (#50611)
* BUG/ENH: infer_freq with non-nano * update test
1 parent 8b96ef2 commit d3995f7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pandas/tests/tseries/frequencies/test_inference.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,13 @@ def test_infer_freq_non_nano():
527527
tda = TimedeltaArray._simple_new(arr2, dtype=arr2.dtype)
528528
res2 = frequencies.infer_freq(tda)
529529
assert res2 == "L"
530+
531+
532+
def test_infer_freq_non_nano_tzaware(tz_aware_fixture):
533+
tz = tz_aware_fixture
534+
535+
dti = date_range("2016-01-01", periods=365, freq="B", tz=tz)
536+
dta = dti._data.as_unit("s")
537+
538+
res = frequencies.infer_freq(dta)
539+
assert res == "B"

pandas/tseries/frequencies.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ def __init__(self, index) -> None:
200200
# the timezone so they are in local time
201201
if hasattr(index, "tz"):
202202
if index.tz is not None:
203-
self.i8values = tz_convert_from_utc(self.i8values, index.tz)
203+
self.i8values = tz_convert_from_utc(
204+
self.i8values, index.tz, reso=self._creso
205+
)
204206

205207
if len(index) < 3:
206208
raise ValueError("Need at least 3 dates to infer frequency")
@@ -395,7 +397,7 @@ def _is_business_daily(self) -> bool:
395397

396398
# probably business daily, but need to confirm
397399
first_weekday = self.index[0].weekday()
398-
shifts = np.diff(self.index.asi8)
400+
shifts = np.diff(self.i8values)
399401
ppd = periods_per_day(self._creso)
400402
shifts = np.floor_divide(shifts, ppd)
401403
weekdays = np.mod(first_weekday + np.cumsum(shifts), 7)

0 commit comments

Comments
 (0)