Skip to content

BUG/ENH: infer_freq with non-nano #50611

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

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions pandas/tests/tseries/frequencies/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,13 @@ def test_infer_freq_non_nano():
tda = TimedeltaArray._simple_new(arr2, dtype=arr2.dtype)
res2 = frequencies.infer_freq(tda)
assert res2 == "L"


def test_infer_freq_non_nano_tzaware(tz_aware_fixture):
tz = tz_aware_fixture

dti = date_range("2016-01-01", periods=365, freq="B", tz=tz)
dta = dti._data.as_unit("s")

res = frequencies.infer_freq(dta)
assert res == "B"
6 changes: 4 additions & 2 deletions pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def __init__(self, index) -> None:
# the timezone so they are in local time
if hasattr(index, "tz"):
if index.tz is not None:
self.i8values = tz_convert_from_utc(self.i8values, index.tz)
self.i8values = tz_convert_from_utc(
self.i8values, index.tz, reso=self._creso
)

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

# probably business daily, but need to confirm
first_weekday = self.index[0].weekday()
shifts = np.diff(self.index.asi8)
shifts = np.diff(self.i8values)
ppd = periods_per_day(self._creso)
shifts = np.floor_divide(shifts, ppd)
weekdays = np.mod(first_weekday + np.cumsum(shifts), 7)
Expand Down