From 0382f204a8f3fa72db433232cbd7d6d4bd66d823 Mon Sep 17 00:00:00 2001 From: Gregory Rome Date: Wed, 15 May 2019 18:46:51 -0500 Subject: [PATCH] Fix type annotations in pandas.core.resample (#26398) --- mypy.ini | 3 --- pandas/core/groupby/grouper.py | 4 +++- pandas/core/resample.py | 22 ++++++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/mypy.ini b/mypy.ini index f6d528a13de2f..169fa546f89e8 100644 --- a/mypy.ini +++ b/mypy.ini @@ -29,9 +29,6 @@ ignore_errors=True [mypy-pandas.core.panel] ignore_errors=True -[mypy-pandas.core.resample] -ignore_errors=True - [mypy-pandas.core.reshape.merge] ignore_errors=True diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 5733586770441..63931dda6acb2 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -3,6 +3,7 @@ split-apply-combine paradigm. """ +from typing import Tuple import warnings import numpy as np @@ -84,7 +85,8 @@ class Grouper: >>> df.groupby(Grouper(level='date', freq='60s', axis=1)) """ - _attributes = ('key', 'level', 'freq', 'axis', 'sort') + _attributes = ('key', 'level', 'freq', 'axis', + 'sort') # type: Tuple[str, ...] def __new__(cls, *args, **kwargs): if kwargs.get('freq') is not None: diff --git a/pandas/core/resample.py b/pandas/core/resample.py index b2d30b5f34a75..7bf0c56c42214 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -1,6 +1,7 @@ import copy from datetime import timedelta from textwrap import dedent +from typing import Dict, no_type_check import warnings import numpy as np @@ -31,7 +32,7 @@ from pandas.tseries.frequencies import to_offset from pandas.tseries.offsets import DateOffset, Day, Nano, Tick -_shared_docs_kwargs = dict() +_shared_docs_kwargs = dict() # type: Dict[str, str] class Resampler(_GroupBy): @@ -873,25 +874,25 @@ def f(self, _method=method, min_count=0, *args, **kwargs): for method in ['min', 'max', 'first', 'last', 'mean', 'sem', 'median', 'ohlc']: - def f(self, _method=method, *args, **kwargs): + def g(self, _method=method, *args, **kwargs): nv.validate_resampler_func(_method, args, kwargs) return self._downsample(_method) - f.__doc__ = getattr(GroupBy, method).__doc__ - setattr(Resampler, method, f) + g.__doc__ = getattr(GroupBy, method).__doc__ + setattr(Resampler, method, g) # groupby & aggregate methods for method in ['count']: - def f(self, _method=method): + def h(self, _method=method): return self._downsample(_method) - f.__doc__ = getattr(GroupBy, method).__doc__ - setattr(Resampler, method, f) + h.__doc__ = getattr(GroupBy, method).__doc__ + setattr(Resampler, method, h) # series only methods for method in ['nunique']: - def f(self, _method=method): + def h(self, _method=method): return self._downsample(_method) - f.__doc__ = getattr(SeriesGroupBy, method).__doc__ - setattr(Resampler, method, f) + h.__doc__ = getattr(SeriesGroupBy, method).__doc__ + setattr(Resampler, method, h) def _maybe_process_deprecations(r, how=None, fill_method=None, limit=None): @@ -964,6 +965,7 @@ def __init__(self, obj, *args, **kwargs): self._groupby.grouper.mutated = True self.groupby = copy.copy(parent.groupby) + @no_type_check def _apply(self, f, grouper=None, *args, **kwargs): """ Dispatch to _upsample; we are stripping all of the _upsample kwargs and