Skip to content

TYP: check_untyped_defs pandas.core.resample #34692

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
Jun 13, 2020
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
11 changes: 9 additions & 2 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def _new_PeriodIndex(cls, **d):


@inherit_names(
["strftime", "to_timestamp", "asfreq", "start_time", "end_time"]
+ PeriodArray._field_ops,
["strftime", "to_timestamp", "start_time", "end_time"] + PeriodArray._field_ops,
PeriodArray,
wrap=True,
)
Expand Down Expand Up @@ -152,6 +151,14 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index):
_engine_type = libindex.PeriodEngine
_supports_partial_string_indexing = True

# --------------------------------------------------------------------
# methods that dispatch to array and wrap result in PeriodIndex

@doc(PeriodArray.asfreq)
def asfreq(self, freq=None, how: str = "E") -> "PeriodIndex":
arr = self._data.asfreq(freq, how)
return type(self)._simple_new(arr, name=self.name)

# ------------------------------------------------------------------------
# Index Constructors

Expand Down
12 changes: 7 additions & 5 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,8 @@ def __init__(self, obj, *args, **kwargs):
for attr in self._attributes:
setattr(self, attr, kwargs.get(attr, getattr(parent, attr)))

super().__init__(None)
# error: Too many arguments for "__init__" of "object"
super().__init__(None) # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

If reading the error message correctly can probably just delete this line instead of ignoring

Copy link
Member Author

Choose a reason for hiding this comment

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

This is in a mixin, so mypy thinks super() is object.

in use, if the class using the mixin is say DatetimeIndexResamplerGroupby, super() is Resampler where init has the signature is def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs): and has a required parameter obj, hence the None here.

if we delete this line tests will fail.

========================================================================= short test summary info ========================================================================== 
FAILED pandas/tests/resample/test_datetime_index.py::test_resample_apply_with_additional_args - AttributeError: 'DatetimeIndexResamplerGroupby' object has no attribute 'b...
FAILED pandas/tests/resample/test_resampler_grouper.py::test_apply - AttributeError: 'DatetimeIndexResamplerGroupby' object has no attribute 'binner'
============================================== 2 failed, 1670 passed, 10 skipped, 1 xfailed, 2 warnings in 548.51s (0:09:08) ===============================================

self._groupby = groupby
self._groupby.mutated = True
self._groupby.grouper.mutated = True
Expand Down Expand Up @@ -1553,7 +1554,7 @@ def _get_time_delta_bins(self, ax):

return binner, bins, labels

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

end_stamps = (labels + freq).asfreq(freq, "s").to_timestamp()
if ax.tzinfo:
end_stamps = end_stamps.tz_localize(ax.tzinfo)
if ax.tz:
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

whats the question? these should be equivalent

end_stamps = end_stamps.tz_localize(ax.tz)
bins = ax.searchsorted(end_stamps, side="left")

return binner, bins, labels

def _get_period_bins(self, ax):
def _get_period_bins(self, ax: PeriodIndex):
if not isinstance(ax, PeriodIndex):
raise TypeError(
"axis must be a PeriodIndex, but got "
Expand Down Expand Up @@ -1898,6 +1899,7 @@ def _asfreq_compat(index, freq):
raise ValueError(
"Can only set arbitrary freq for empty DatetimeIndex or TimedeltaIndex"
)
new_index: Index
if isinstance(index, PeriodIndex):
new_index = index.asfreq(freq=freq)
else:
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@ check_untyped_defs=False
[mypy-pandas.core.ops.docstrings]
check_untyped_defs=False

[mypy-pandas.core.resample]
check_untyped_defs=False

[mypy-pandas.core.reshape.merge]
check_untyped_defs=False

Expand Down