From ac8a7140ef0a4123365ef46c7b84df63cd14ba5c Mon Sep 17 00:00:00 2001 From: Gregory Rome Date: Tue, 14 May 2019 09:27:48 -0500 Subject: [PATCH 1/2] Begin correctin type annotations in core.resample --- mypy.ini | 3 --- pandas/core/groupby/grouper.py | 4 +++- pandas/core/resample.py | 21 +++++++++++---------- 3 files changed, 14 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..65f0283b04f43 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..787989e0284df 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 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): From 1abd09967397af331b51169e46a57f401d7b10cf Mon Sep 17 00:00:00 2001 From: Gregory Rome Date: Tue, 14 May 2019 10:25:46 -0500 Subject: [PATCH 2/2] Suppress type checking for _GroupByMixin._apply --- pandas/core/groupby/grouper.py | 2 +- pandas/core/resample.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 65f0283b04f43..63931dda6acb2 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -3,7 +3,7 @@ split-apply-combine paradigm. """ -from Typing import Tuple +from typing import Tuple import warnings import numpy as np diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 787989e0284df..7bf0c56c42214 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -1,7 +1,7 @@ import copy from datetime import timedelta from textwrap import dedent -from typing import Dict +from typing import Dict, no_type_check import warnings import numpy as np @@ -965,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