Skip to content
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

Misc Type Annotation fixes #26372

Merged
merged 14 commits into from
May 18, 2019
33 changes: 0 additions & 33 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,8 @@ 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.ops]
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

[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
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
5 changes: 3 additions & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import textwrap
from typing import Type
import warnings

import numpy as np
Expand Down Expand Up @@ -88,8 +89,8 @@ class IndexingError(Exception):


class _NDFrameIndexer(_NDFrameIndexerBase):
_valid_types = None
_exception = KeyError
_valid_types = None # type: str
_exception = KeyError # type: Type[Exception]
gwrome marked this conversation as resolved.
Show resolved Hide resolved
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

gwrome marked this conversation as resolved.
Show resolved Hide resolved
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
13 changes: 9 additions & 4 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, no_type_check
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
gwrome marked this conversation as resolved.
Show resolved Hide resolved

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):
gwrome marked this conversation as resolved.
Show resolved Hide resolved
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,6 +789,10 @@ def __init__(self, obj, *args, **kwargs):
corr = GroupByMixin._dispatch('corr', other=None, pairwise=None)
cov = GroupByMixin._dispatch('cov', other=None, pairwise=None)

# Removed from type checking because there is currently no good way to
# handle multiple inheritance with mypy
# https://github.com/python/mypy/issues/2125
@no_type_check
gwrome marked this conversation as resolved.
Show resolved Hide resolved
def _apply(self, func, name, window=None, center=None,
check_minp=None, **kwargs):
"""
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
gwrome marked this conversation as resolved.
Show resolved Hide resolved

# 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: Optional[str]
gwrome marked this conversation as resolved.
Show resolved Hide resolved
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