Skip to content

Commit 99ce0e7

Browse files
check_untyped_defs pandas.core.generic
1 parent 2054965 commit 99ce0e7

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

pandas/core/generic.py

+26-18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import re
99
from textwrap import dedent
1010
from typing import (
11+
TYPE_CHECKING,
1112
Any,
1213
Callable,
1314
Dict,
@@ -18,6 +19,7 @@
1819
Sequence,
1920
Set,
2021
Union,
22+
cast,
2123
)
2224
import warnings
2325
import weakref
@@ -88,6 +90,9 @@
8890
from pandas.io.formats.printing import pprint_thing
8991
from pandas.tseries.frequencies import to_offset
9092

93+
if TYPE_CHECKING:
94+
from pandas import Series # noqa: F401
95+
9196
# goal is to be able to define the docs close to function, while still being
9297
# able to share
9398
_shared_docs = dict() # type: Dict[str, str]
@@ -458,7 +463,7 @@ def _get_block_manager_axis(cls, axis):
458463
return m - axis
459464
return axis
460465

461-
def _get_axis_resolvers(self, axis):
466+
def _get_axis_resolvers(self, axis: str) -> Dict[str, Union["Series", MultiIndex]]:
462467
# index or columns
463468
axis_index = getattr(self, axis)
464469
d = dict()
@@ -488,8 +493,8 @@ def _get_axis_resolvers(self, axis):
488493
d[axis] = dindex
489494
return d
490495

491-
def _get_index_resolvers(self):
492-
d = {}
496+
def _get_index_resolvers(self) -> Dict[str, Union["Series", MultiIndex]]:
497+
d: Dict[str, Union["Series", MultiIndex]] = {}
493498
for axis_name in self._AXIS_ORDERS:
494499
d.update(self._get_axis_resolvers(axis_name))
495500
return d
@@ -2057,7 +2062,7 @@ def __setstate__(self, state):
20572062
# old pickling format, for compatibility
20582063
self._unpickle_matrix_compat(state)
20592064

2060-
self._item_cache = {}
2065+
self._item_cache: Dict = {}
20612066

20622067
# ----------------------------------------------------------------------
20632068
# Rendering Methods
@@ -3556,9 +3561,9 @@ class animal locomotion
35563561
loc, new_ax = labels.get_loc_level(key, level=level, drop_level=drop_level)
35573562

35583563
# create the tuple of the indexer
3559-
indexer = [slice(None)] * self.ndim
3560-
indexer[axis] = loc
3561-
indexer = tuple(indexer)
3564+
indexer_ = [slice(None)] * self.ndim
3565+
indexer_[axis] = loc
3566+
indexer = tuple(indexer_)
35623567

35633568
result = self.iloc[indexer]
35643569
setattr(result, result._get_axis_name(axis), new_ax)
@@ -5598,7 +5603,7 @@ def get_dtype_counts(self):
55985603
stacklevel=2,
55995604
)
56005605

5601-
from pandas import Series
5606+
from pandas import Series # noqa: F811
56025607

56035608
return Series(self._data.get_dtype_counts())
56045609

@@ -5641,7 +5646,7 @@ def get_ftype_counts(self):
56415646
stacklevel=2,
56425647
)
56435648

5644-
from pandas import Series
5649+
from pandas import Series # noqa: F811
56455650

56465651
return Series(self._data.get_ftype_counts())
56475652

@@ -5677,7 +5682,7 @@ def dtypes(self):
56775682
string object
56785683
dtype: object
56795684
"""
5680-
from pandas import Series
5685+
from pandas import Series # noqa: F811
56815686

56825687
return Series(self._data.get_dtypes(), index=self._info_axis, dtype=np.object_)
56835688

@@ -5726,7 +5731,7 @@ def ftypes(self):
57265731
stacklevel=2,
57275732
)
57285733

5729-
from pandas import Series
5734+
from pandas import Series # noqa: F811
57305735

57315736
return Series(self._data.get_ftypes(), index=self._info_axis, dtype=np.object_)
57325737

@@ -5905,10 +5910,10 @@ def astype(self, dtype, copy=True, errors="raise"):
59055910
elif is_extension_array_dtype(dtype) and self.ndim > 1:
59065911
# GH 18099/22869: columnwise conversion to extension dtype
59075912
# GH 24704: use iloc to handle duplicate column names
5908-
results = (
5913+
results = [
59095914
self.iloc[:, i].astype(dtype, copy=copy)
59105915
for i in range(len(self.columns))
5911-
)
5916+
]
59125917

59135918
else:
59145919
# else, only a single dtype is given
@@ -6277,7 +6282,7 @@ def fillna(
62776282

62786283
if self.ndim == 1:
62796284
if isinstance(value, (dict, ABCSeries)):
6280-
from pandas import Series
6285+
from pandas import Series # noqa: F811
62816286

62826287
value = Series(value)
62836288
elif not is_list_like(value):
@@ -6681,8 +6686,11 @@ def replace(
66816686
to_replace = regex
66826687
regex = True
66836688

6684-
items = list(to_replace.items())
6685-
keys, values = zip(*items) if items else ([], [])
6689+
items = list(cast(dict, to_replace).items())
6690+
if items:
6691+
keys, values = zip(*items)
6692+
else:
6693+
keys, values = ([], [])
66866694

66876695
are_mappings = [is_dict_like(v) for v in values]
66886696

@@ -7219,7 +7227,7 @@ def asof(self, where, subset=None):
72197227

72207228
if where < start:
72217229
if not is_series:
7222-
from pandas import Series
7230+
from pandas import Series # noqa: F811
72237231

72247232
return Series(index=self.columns, name=where)
72257233
return np.nan
@@ -10266,7 +10274,7 @@ def describe_1d(data):
1026610274

1026710275
ldesc = [describe_1d(s) for _, s in data.items()]
1026810276
# set a convenient order for rows
10269-
names = []
10277+
names: List = []
1027010278
ldesc_indexes = sorted((x.index for x in ldesc), key=len)
1027110279
for idxnames in ldesc_indexes:
1027210280
for name in idxnames:

setup.cfg

-3
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ check_untyped_defs=False
182182
[mypy-pandas.core.frame]
183183
check_untyped_defs=False
184184

185-
[mypy-pandas.core.generic]
186-
check_untyped_defs=False
187-
188185
[mypy-pandas.core.indexes.datetimes]
189186
check_untyped_defs=False
190187

0 commit comments

Comments
 (0)