Skip to content

Misc Type Annotation fixes #26372

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 14 commits into from
May 18, 2019
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Other API Changes
- Comparing :class:`Timestamp` with unsupported objects now returns :py:obj:`NotImplemented` instead of raising ``TypeError``. This implies that unsupported rich comparisons are delegated to the other object, and are now consistent with Python 3 behavior for ``datetime`` objects (:issue:`24011`)
- Bug in :meth:`DatetimeIndex.snap` which didn't preserving the ``name`` of the input :class:`Index` (:issue:`25575`)
- The ``arg`` argument in :meth:`pandas.core.groupby.DataFrameGroupBy.agg` has been renamed to ``func`` (:issue:`26089`)
- The ``arg`` argument in :meth:`pandas.core.window._Window.aggregate` has been renamed to ``func`` (:issue:`26372`)

.. _whatsnew_0250.deprecations:

Expand Down
35 changes: 1 addition & 34 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,4 @@ ignore_errors=True
ignore_errors=True

[mypy-pandas.core.indexes.timedeltas]
ignore_errors=True

[mypy-pandas.core.indexing]
ignore_errors=True

[mypy-pandas.core.internals.blocks]
ignore_errors=True

[mypy-pandas.core.panel]
ignore_errors=True

[mypy-pandas.core.reshape.merge]
ignore_errors=True

[mypy-pandas.core.reshape.reshape]
ignore_errors=True

[mypy-pandas.core.series]
ignore_errors=True

[mypy-pandas.core.util.hashing]
ignore_errors=True

[mypy-pandas.core.window]
ignore_errors=True

[mypy-pandas.io.pytables]
ignore_errors=True

[mypy-pandas.util._doctools]
ignore_errors=True

[mypy-pandas.util.testing]
ignore_errors=True
ignore_errors=True
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1572,5 +1572,5 @@ def duplicated(self, keep='first'):
# ----------------------------------------------------------------------
# abstracts

def _update_inplace(self, result, **kwargs):
def _update_inplace(self, result, verify_is_copy=True, **kwargs):
raise AbstractMethodError(self)
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import operator
import pickle
from textwrap import dedent
from typing import FrozenSet, List, Set
from typing import Callable, FrozenSet, List, Set
import warnings
import weakref

Expand Down Expand Up @@ -3680,7 +3680,7 @@ class animal locomotion
result._set_is_copy(self, copy=not result._is_view)
return result

_xs = xs
_xs = xs # type: Callable

def select(self, crit, axis=0):
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class IndexingError(Exception):


class _NDFrameIndexer(_NDFrameIndexerBase):
_valid_types = None
_exception = KeyError
_valid_types = None # type: str
_exception = Exception
axis = None

def __call__(self, axis=None):
Expand Down
8 changes: 6 additions & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import numpy as np

from pandas._libs import internals as libinternals, lib, tslib, tslibs
from pandas._libs import lib, tslib, tslibs
import pandas._libs.internals as libinternals
from pandas._libs.tslibs import Timedelta, conversion, is_null_datetimelike
from pandas.util._validators import validate_bool_kwarg

Expand Down Expand Up @@ -2050,12 +2051,15 @@ def get_values(self, dtype=None):
class DatetimeBlock(DatetimeLikeBlockMixin, Block):
__slots__ = ()
is_datetime = True
_can_hold_na = True

def __init__(self, values, placement, ndim=None):
values = self._maybe_coerce_values(values)
super().__init__(values, placement=placement, ndim=ndim)

@property
def _can_hold_na(self):
return True

def _maybe_coerce_values(self, values):
"""Input validation for values passed to __init__. Ensure that
we have datetime64ns, coercing if necessary.
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import numpy as np

from pandas._libs import hashtable as libhashtable, join as libjoin, lib
from pandas._libs import hashtable as libhashtable, lib
import pandas._libs.join as libjoin
from pandas.errors import MergeError
from pandas.util._decorators import Appender, Substitution

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import numpy as np

from pandas._libs import algos as _algos, reshape as _reshape
import pandas._libs.algos as _algos
import pandas._libs.reshape as _reshape
from pandas._libs.sparse import IntIndex

from pandas.core.dtypes.cast import maybe_promote
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/util/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import numpy as np

from pandas._libs import hashing, tslibs
import pandas._libs.hashing as hashing
import pandas._libs.tslibs as tslibs

from pandas.core.dtypes.cast import infer_dtype_from_scalar
from pandas.core.dtypes.common import (
Expand Down
11 changes: 6 additions & 5 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import defaultdict
from datetime import timedelta
from textwrap import dedent
from typing import Set
import warnings

import numpy as np
Expand Down Expand Up @@ -42,7 +43,7 @@
class _Window(PandasObject, SelectionMixin):
_attributes = ['window', 'min_periods', 'center', 'win_type',
'axis', 'on', 'closed']
exclusions = set()
exclusions = set() # type: Set[str]

def __init__(self, obj, window=None, min_periods=None,
center=False, win_type=None, axis=0, on=None, closed=None,
Expand Down Expand Up @@ -305,10 +306,10 @@ def _center_window(self, result, window):
result = np.copy(result[tuple(lead_indexer)])
return result

def aggregate(self, arg, *args, **kwargs):
result, how = self._aggregate(arg, *args, **kwargs)
def aggregate(self, func, *args, **kwargs):
result, how = self._aggregate(func, *args, **kwargs)
if result is None:
return self.apply(arg, raw=False, args=args, kwargs=kwargs)
return self.apply(func, raw=False, args=args, kwargs=kwargs)
return result

agg = aggregate
Expand Down Expand Up @@ -788,7 +789,7 @@ def __init__(self, obj, *args, **kwargs):
corr = GroupByMixin._dispatch('corr', other=None, pairwise=None)
cov = GroupByMixin._dispatch('cov', other=None, pairwise=None)

def _apply(self, func, name, window=None, center=None,
def _apply(self, func, name=None, window=None, center=None,
check_minp=None, **kwargs):
"""
Dispatch to apply; we are stripping all of the _apply kwargs and
Expand Down
15 changes: 8 additions & 7 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import re
import time
from typing import List, Optional, Type, Union
import warnings

import numpy as np
Expand Down Expand Up @@ -2297,9 +2298,9 @@ class Fixed(StringMixin):
parent : my parent HDFStore
group : the group node where the table resides
"""
pandas_kind = None
obj_type = None
ndim = None
pandas_kind = None # type: str
obj_type = None # type: Type[Union[DataFrame, Series]]
ndim = None # type: int
is_table = False

def __init__(self, parent, group, encoding=None, errors='strict',
Expand Down Expand Up @@ -2459,7 +2460,7 @@ class GenericFixed(Fixed):
""" a generified fixed version """
_index_type_map = {DatetimeIndex: 'datetime', PeriodIndex: 'period'}
_reverse_index_map = {v: k for k, v in _index_type_map.items()}
attributes = []
attributes = [] # type: List[str]

# indexer helpders
def _class_to_alias(self, cls):
Expand Down Expand Up @@ -3052,7 +3053,7 @@ class Table(Fixed):

"""
pandas_kind = 'wide_table'
table_type = None
table_type = None # type: str
levels = 1
is_table = True
is_shape_reversed = False
Expand Down Expand Up @@ -3873,7 +3874,7 @@ class LegacyTable(Table):
IndexCol(name='index', axis=1, pos=0),
IndexCol(name='column', axis=2, pos=1, index_kind='columns_kind'),
DataCol(name='fields', cname='values', kind_attr='fields', pos=2)
]
] # type: Optional[List[IndexCol]]
table_type = 'legacy'
ndim = 3

Expand Down Expand Up @@ -4126,7 +4127,7 @@ class AppendableFrameTable(AppendableTable):
pandas_kind = 'frame_table'
table_type = 'appendable_frame'
ndim = 2
obj_type = DataFrame
obj_type = DataFrame # type: Type[Union[DataFrame, Series]]

@property
def is_transposed(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pandas._config.localization import ( # noqa:F401
can_set_locale, get_locales, set_locale)

from pandas._libs import testing as _testing
import pandas._libs.testing as _testing
from pandas.compat import raise_with_traceback

from pandas.core.dtypes.common import (
Expand Down