Skip to content

Commit

Permalink
Fix type annotations in pandas.core.resample (pandas-dev#26398)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwrome authored and jreback committed May 15, 2019
1 parent e101dd9 commit 0382f20
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
split-apply-combine paradigm.
"""

from typing import Tuple
import warnings

import numpy as np
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 12 additions & 10 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0382f20

Please sign in to comment.