Skip to content

Commit aaf4b7b

Browse files
TYP: check_untyped_defs pandas.core.resample (#34692)
1 parent 398b563 commit aaf4b7b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

pandas/core/indexes/period.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ def _new_PeriodIndex(cls, **d):
6464

6565

6666
@inherit_names(
67-
["strftime", "to_timestamp", "asfreq", "start_time", "end_time"]
68-
+ PeriodArray._field_ops,
67+
["strftime", "to_timestamp", "start_time", "end_time"] + PeriodArray._field_ops,
6968
PeriodArray,
7069
wrap=True,
7170
)
@@ -152,6 +151,14 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index):
152151
_engine_type = libindex.PeriodEngine
153152
_supports_partial_string_indexing = True
154153

154+
# --------------------------------------------------------------------
155+
# methods that dispatch to array and wrap result in PeriodIndex
156+
157+
@doc(PeriodArray.asfreq)
158+
def asfreq(self, freq=None, how: str = "E") -> "PeriodIndex":
159+
arr = self._data.asfreq(freq, how)
160+
return type(self)._simple_new(arr, name=self.name)
161+
155162
# ------------------------------------------------------------------------
156163
# Index Constructors
157164

pandas/core/resample.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,8 @@ def __init__(self, obj, *args, **kwargs):
966966
for attr in self._attributes:
967967
setattr(self, attr, kwargs.get(attr, getattr(parent, attr)))
968968

969-
super().__init__(None)
969+
# error: Too many arguments for "__init__" of "object"
970+
super().__init__(None) # type: ignore
970971
self._groupby = groupby
971972
self._groupby.mutated = True
972973
self._groupby.grouper.mutated = True
@@ -1553,7 +1554,7 @@ def _get_time_delta_bins(self, ax):
15531554

15541555
return binner, bins, labels
15551556

1556-
def _get_time_period_bins(self, ax):
1557+
def _get_time_period_bins(self, ax: DatetimeIndex):
15571558
if not isinstance(ax, DatetimeIndex):
15581559
raise TypeError(
15591560
"axis must be a DatetimeIndex, but got "
@@ -1569,13 +1570,13 @@ def _get_time_period_bins(self, ax):
15691570
labels = binner = period_range(start=ax[0], end=ax[-1], freq=freq, name=ax.name)
15701571

15711572
end_stamps = (labels + freq).asfreq(freq, "s").to_timestamp()
1572-
if ax.tzinfo:
1573-
end_stamps = end_stamps.tz_localize(ax.tzinfo)
1573+
if ax.tz:
1574+
end_stamps = end_stamps.tz_localize(ax.tz)
15741575
bins = ax.searchsorted(end_stamps, side="left")
15751576

15761577
return binner, bins, labels
15771578

1578-
def _get_period_bins(self, ax):
1579+
def _get_period_bins(self, ax: PeriodIndex):
15791580
if not isinstance(ax, PeriodIndex):
15801581
raise TypeError(
15811582
"axis must be a PeriodIndex, but got "
@@ -1898,6 +1899,7 @@ def _asfreq_compat(index, freq):
18981899
raise ValueError(
18991900
"Can only set arbitrary freq for empty DatetimeIndex or TimedeltaIndex"
19001901
)
1902+
new_index: Index
19011903
if isinstance(index, PeriodIndex):
19021904
new_index = index.asfreq(freq=freq)
19031905
else:

setup.cfg

-3
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,6 @@ check_untyped_defs=False
214214
[mypy-pandas.core.ops.docstrings]
215215
check_untyped_defs=False
216216

217-
[mypy-pandas.core.resample]
218-
check_untyped_defs=False
219-
220217
[mypy-pandas.core.reshape.merge]
221218
check_untyped_defs=False
222219

0 commit comments

Comments
 (0)