From 30daa585e0557b3a227198123603b2753fdf30b5 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 10:07:32 +0100 Subject: [PATCH 01/45] [mypy-pandas._testing] --- pandas/_testing.py | 71 ++++++++++++++++++++++++++++++++++++---------- setup.cfg | 3 -- 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/pandas/_testing.py b/pandas/_testing.py index cf6272edc4c05..eb9010bab7805 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -116,14 +116,24 @@ def set_testing_mode(): # set the testing mode filters testing_mode = os.environ.get("PANDAS_TESTING_MODE", "None") if "deprecate" in testing_mode: - warnings.simplefilter("always", _testing_mode_warnings) + # pandas\_testing.py:119: error: Argument 2 to "simplefilter" has + # incompatible type "Tuple[Type[DeprecationWarning], + # Type[ResourceWarning]]"; expected "Type[Warning]" + warnings.simplefilter( + "always", _testing_mode_warnings # type: ignore[arg-type] + ) def reset_testing_mode(): # reset the testing mode filters testing_mode = os.environ.get("PANDAS_TESTING_MODE", "None") if "deprecate" in testing_mode: - warnings.simplefilter("ignore", _testing_mode_warnings) + # pandas\_testing.py:126: error: Argument 2 to "simplefilter" has + # incompatible type "Tuple[Type[DeprecationWarning], + # Type[ResourceWarning]]"; expected "Type[Warning]" + warnings.simplefilter( + "ignore", _testing_mode_warnings # type: ignore[arg-type] + ) set_testing_mode() @@ -240,16 +250,22 @@ def decompress_file(path, compression): if compression is None: f = open(path, "rb") elif compression == "gzip": - f = gzip.open(path, "rb") + # pandas\_testing.py:243: error: Incompatible types in assignment + # (expression has type "IO[Any]", variable has type "BinaryIO") + f = gzip.open(path, "rb") # type: ignore[assignment] elif compression == "bz2": - f = bz2.BZ2File(path, "rb") + # pandas\_testing.py:245: error: Incompatible types in assignment + # (expression has type "BZ2File", variable has type "BinaryIO") + f = bz2.BZ2File(path, "rb") # type: ignore[assignment] elif compression == "xz": f = get_lzma_file(lzma)(path, "rb") elif compression == "zip": zip_file = zipfile.ZipFile(path) zip_names = zip_file.namelist() if len(zip_names) == 1: - f = zip_file.open(zip_names.pop()) + # pandas\_testing.py:252: error: Incompatible types in assignment + # (expression has type "IO[bytes]", variable has type "BinaryIO") + f = zip_file.open(zip_names.pop()) # type: ignore[assignment] else: raise ValueError(f"ZIP file {path} error. Only one file per ZIP.") else: @@ -285,9 +301,15 @@ def write_to_compressed(compression, path, data, dest="test"): if compression == "zip": compress_method = zipfile.ZipFile elif compression == "gzip": - compress_method = gzip.GzipFile + # pandas\_testing.py:288: error: Incompatible types in assignment + # (expression has type "Type[GzipFile]", variable has type + # "Type[ZipFile]") + compress_method = gzip.GzipFile # type: ignore[assignment] elif compression == "bz2": - compress_method = bz2.BZ2File + # pandas\_testing.py:290: error: Incompatible types in assignment + # (expression has type "Type[BZ2File]", variable has type + # "Type[ZipFile]") + compress_method = bz2.BZ2File # type: ignore[assignment] elif compression == "xz": compress_method = get_lzma_file(lzma) else: @@ -299,7 +321,10 @@ def write_to_compressed(compression, path, data, dest="test"): method = "writestr" else: mode = "wb" - args = (data,) + # pandas\_testing.py:302: error: Incompatible types in assignment + # (expression has type "Tuple[Any]", variable has type "Tuple[Any, + # Any]") + args = (data,) # type: ignore[assignment] method = "write" with compress_method(path, mode=mode) as f: @@ -1983,7 +2008,8 @@ def all_timeseries_index_generator(k=10): """ make_index_funcs = [makeDateIndex, makePeriodIndex, makeTimedeltaIndex] for make_index_func in make_index_funcs: - yield make_index_func(k=k) + # pandas\_testing.py:1986: error: Cannot call function of unknown type + yield make_index_func(k=k) # type: ignore[operator] # make series @@ -2117,7 +2143,8 @@ def makeCustomIndex( p=makePeriodIndex, ).get(idx_type) if idx_func: - idx = idx_func(nentries) + # pandas\_testing.py:2120: error: Cannot call function of unknown type + idx = idx_func(nentries) # type: ignore[operator] # but we need to fill in the name if names: idx.name = names[0] @@ -2145,7 +2172,8 @@ def keyfunc(x): # build a list of lists to create the index from div_factor = nentries // ndupe_l[i] + 1 - cnt = Counter() + # pandas\_testing.py:2148: error: Need type annotation for 'cnt' + cnt = Counter() # type: ignore[var-annotated] for j in range(div_factor): label = f"{prefix}_l{i}_g{j}" cnt[label] = ndupe_l[i] @@ -2303,7 +2331,14 @@ def _gen_unique_rand(rng, _extra_size): def makeMissingDataframe(density=0.9, random_state=None): df = makeDataFrame() - i, j = _create_missing_idx(*df.shape, density=density, random_state=random_state) + # pandas\_testing.py:2306: error: "_create_missing_idx" gets multiple + # values for keyword argument "density" [misc] + + # pandas\_testing.py:2306: error: "_create_missing_idx" gets multiple + # values for keyword argument "random_state" [misc] + i, j = _create_missing_idx( # type: ignore[misc] + *df.shape, density=density, random_state=random_state + ) df.values[i, j] = np.nan return df @@ -2328,7 +2363,10 @@ def dec(f): is_decorating = not kwargs and len(args) == 1 and callable(args[0]) if is_decorating: f = args[0] - args = [] + # pandas\_testing.py:2331: error: Incompatible types in assignment + # (expression has type "List[]", variable has type + # "Tuple[Any, ...]") + args = [] # type: ignore[assignment] return dec(f) else: return dec @@ -2518,7 +2556,9 @@ def wrapper(*args, **kwargs): except Exception as err: errno = getattr(err, "errno", None) if not errno and hasattr(errno, "reason"): - errno = getattr(err.reason, "errno", None) + # pandas\_testing.py:2521: error: "Exception" has no attribute + # "reason" + errno = getattr(err.reason, "errno", None) # type: ignore[attr-defined] if errno in skip_errnos: skip(f"Skipping test due to known errno and error {err}") @@ -2842,7 +2882,8 @@ def setTZ(tz): pass else: os.environ["TZ"] = tz - time.tzset() + # pandas\_testing.py:2845: error: Module has no attribute "tzset" + time.tzset() # type: ignore[attr-defined] orig_tz = os.environ.get("TZ") setTZ(tz) diff --git a/setup.cfg b/setup.cfg index 73986f692b6cd..4c569979178db 100644 --- a/setup.cfg +++ b/setup.cfg @@ -129,9 +129,6 @@ ignore_errors=True [mypy-pandas.tests.*] check_untyped_defs=False -[mypy-pandas._testing] -check_untyped_defs=False - [mypy-pandas._version] check_untyped_defs=False From 3143012b1b06ef7877d5abfb36e7b48555c0ead2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 10:18:55 +0100 Subject: [PATCH 02/45] [mypy-pandas.compat.pickle_compat] --- pandas/compat/pickle_compat.py | 9 ++++++++- setup.cfg | 3 --- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index ef9f36705a7ee..b98595d2242bb 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -274,7 +274,14 @@ def patch_pickle(): """ orig_loads = pkl.loads try: - pkl.loads = loads + # pandas\compat\pickle_compat.py:277: error: Incompatible types in + # assignment (expression has type "Callable[[bytes, + # DefaultNamedArg(bool, 'fix_imports'), DefaultNamedArg(str, + # 'encoding'), DefaultNamedArg(str, 'errors')], Any]", variable has + # type "Callable[[bytes, DefaultNamedArg(bool, 'fix_imports'), + # DefaultNamedArg(str, 'encoding'), DefaultNamedArg(str, 'errors'), + # DefaultNamedArg(Optional[Iterable[Any]], 'buffers')], Any]") + pkl.loads = loads # type: ignore[assignment] yield finally: pkl.loads = orig_loads diff --git a/setup.cfg b/setup.cfg index 4c569979178db..3375fc8729d0b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.compat.pickle_compat] -check_untyped_defs=False - [mypy-pandas.core.apply] check_untyped_defs=False From 90c9a5fa75e228f399136b79d4d06362c40f64cf Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 10:41:37 +0100 Subject: [PATCH 03/45] [mypy-pandas.core.apply] --- pandas/core/apply.py | 6 +++++- setup.cfg | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 002e260742dc5..aec20d8a606f1 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -141,7 +141,11 @@ def get_result(self): """ compute the results """ # dispatch to agg if is_list_like(self.f) or is_dict_like(self.f): - return self.obj.aggregate(self.f, axis=self.axis, *self.args, **self.kwds) + # pandas\core\apply.py:144: error: "aggregate" of "DataFrame" gets + # multiple values for keyword argument "axis" + return self.obj.aggregate( # type: ignore[misc] + self.f, axis=self.axis, *self.args, **self.kwds + ) # all empty if len(self.columns) == 0 and len(self.index) == 0: diff --git a/setup.cfg b/setup.cfg index 3375fc8729d0b..12dc2aade3eec 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.apply] -check_untyped_defs=False - [mypy-pandas.core.arrays.base] check_untyped_defs=False From 07f3a9e1ed228300bd262664af2d6f10c52a6593 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 11:23:17 +0100 Subject: [PATCH 04/45] [mypy-pandas.core.arrays.base] --- pandas/core/arrays/base.py | 160 ++++++++++++++++++++++++++++++------- setup.cfg | 3 - 2 files changed, 132 insertions(+), 31 deletions(-) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index c2fc72ff753a8..cdf8534b3dacf 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1176,22 +1176,84 @@ def _create_arithmetic_method(cls, op): @classmethod def _add_arithmetic_ops(cls): - cls.__add__ = cls._create_arithmetic_method(operator.add) - cls.__radd__ = cls._create_arithmetic_method(ops.radd) - cls.__sub__ = cls._create_arithmetic_method(operator.sub) - cls.__rsub__ = cls._create_arithmetic_method(ops.rsub) - cls.__mul__ = cls._create_arithmetic_method(operator.mul) - cls.__rmul__ = cls._create_arithmetic_method(ops.rmul) - cls.__pow__ = cls._create_arithmetic_method(operator.pow) - cls.__rpow__ = cls._create_arithmetic_method(ops.rpow) - cls.__mod__ = cls._create_arithmetic_method(operator.mod) - cls.__rmod__ = cls._create_arithmetic_method(ops.rmod) - cls.__floordiv__ = cls._create_arithmetic_method(operator.floordiv) - cls.__rfloordiv__ = cls._create_arithmetic_method(ops.rfloordiv) - cls.__truediv__ = cls._create_arithmetic_method(operator.truediv) - cls.__rtruediv__ = cls._create_arithmetic_method(ops.rtruediv) - cls.__divmod__ = cls._create_arithmetic_method(divmod) - cls.__rdivmod__ = cls._create_arithmetic_method(ops.rdivmod) + # pandas\core\arrays\base.py:1179: error: Unsupported left operand type + # for + ("Type[ExtensionOpsMixin]") [operator] + cls.__add__ = cls._create_arithmetic_method( # type: ignore[operator] + operator.add + ) + # pandas\core\arrays\base.py:1180: error: "Type[ExtensionOpsMixin]" has + # no attribute "__radd__" [attr-defined] + cls.__radd__ = cls._create_arithmetic_method( # type: ignore[attr-defined] + ops.radd + ) + # pandas\core\arrays\base.py:1181: error: Unsupported left operand type + # for - ("Type[ExtensionOpsMixin]") [operator] + cls.__sub__ = cls._create_arithmetic_method( # type: ignore[operator] + operator.sub + ) + # pandas\core\arrays\base.py:1182: error: "Type[ExtensionOpsMixin]" has + # no attribute "__rsub__" [attr-defined] + cls.__rsub__ = cls._create_arithmetic_method( # type: ignore[attr-defined] + ops.rsub + ) + # pandas\core\arrays\base.py:1183: error: Unsupported left operand type + # for * ("Type[ExtensionOpsMixin]") [operator] + cls.__mul__ = cls._create_arithmetic_method( # type: ignore[operator] + operator.mul + ) + # pandas\core\arrays\base.py:1184: error: "Type[ExtensionOpsMixin]" has + # no attribute "__rmul__" [attr-defined] + cls.__rmul__ = cls._create_arithmetic_method( # type: ignore[attr-defined] + ops.rmul + ) + # pandas\core\arrays\base.py:1185: error: Unsupported left operand type + # for ** ("Type[ExtensionOpsMixin]") [operator] + cls.__pow__ = cls._create_arithmetic_method( # type: ignore[operator] + operator.pow + ) + # pandas\core\arrays\base.py:1186: error: "Type[ExtensionOpsMixin]" has + # no attribute "__rpow__" [attr-defined] + cls.__rpow__ = cls._create_arithmetic_method( # type: ignore[attr-defined] + ops.rpow + ) + # pandas\core\arrays\base.py:1187: error: Unsupported left operand type + # for % ("Type[ExtensionOpsMixin]") [operator] + cls.__mod__ = cls._create_arithmetic_method( # type: ignore[operator] + operator.mod + ) + # pandas\core\arrays\base.py:1188: error: "Type[ExtensionOpsMixin]" has + # no attribute "__rmod__" [attr-defined] + cls.__rmod__ = cls._create_arithmetic_method( # type: ignore[attr-defined] + ops.rmod + ) + # pandas\core\arrays\base.py:1189: error: Unsupported left operand type + # for // ("Type[ExtensionOpsMixin]") [operator] + cls.__floordiv__ = cls._create_arithmetic_method( # type: ignore[operator] + operator.floordiv + ) + # pandas\core\arrays\base.py:1190: error: "Type[ExtensionOpsMixin]" has + # no attribute "__rfloordiv__" [attr-defined] + cls.__rfloordiv__ = cls._create_arithmetic_method( # type: ignore[attr-defined] + ops.rfloordiv + ) + # pandas\core\arrays\base.py:1191: error: Unsupported left operand type + # for / ("Type[ExtensionOpsMixin]") [operator] + cls.__truediv__ = cls._create_arithmetic_method( # type: ignore[operator] + operator.truediv + ) + # pandas\core\arrays\base.py:1192: error: "Type[ExtensionOpsMixin]" has + # no attribute "__rtruediv__" [attr-defined] + cls.__rtruediv__ = cls._create_arithmetic_method( # type: ignore[attr-defined] + ops.rtruediv + ) + # pandas\core\arrays\base.py:1193: error: Unsupported left operand type + # for divmod ("Type[ExtensionOpsMixin]") [operator] + cls.__divmod__ = cls._create_arithmetic_method(divmod) # type: ignore[operator] + # pandas\core\arrays\base.py:1194: error: "Type[ExtensionOpsMixin]" has + # no attribute "__rdivmod__" [attr-defined] + cls.__rdivmod__ = cls._create_arithmetic_method( # type: ignore[attr-defined] + ops.rdivmod + ) @classmethod def _create_comparison_method(cls, op): @@ -1199,12 +1261,36 @@ def _create_comparison_method(cls, op): @classmethod def _add_comparison_ops(cls): - cls.__eq__ = cls._create_comparison_method(operator.eq) - cls.__ne__ = cls._create_comparison_method(operator.ne) - cls.__lt__ = cls._create_comparison_method(operator.lt) - cls.__gt__ = cls._create_comparison_method(operator.gt) - cls.__le__ = cls._create_comparison_method(operator.le) - cls.__ge__ = cls._create_comparison_method(operator.ge) + # pandas\core\arrays\base.py:1202: error: Cannot assign to a method + # [assignment] + cls.__eq__ = cls._create_comparison_method( # type: ignore[assignment] + operator.eq + ) + # pandas\core\arrays\base.py:1203: error: Cannot assign to a method + # [assignment] + cls.__ne__ = cls._create_comparison_method( # type: ignore[assignment] + operator.ne + ) + # pandas\core\arrays\base.py:1204: error: Unsupported left operand type + # for < ("Type[ExtensionOpsMixin]") [operator] + cls.__lt__ = cls._create_comparison_method( # type: ignore[operator] + operator.lt + ) + # pandas\core\arrays\base.py:1205: error: Unsupported left operand type + # for > ("Type[ExtensionOpsMixin]") [operator] + cls.__gt__ = cls._create_comparison_method( # type: ignore[operator] + operator.gt + ) + # pandas\core\arrays\base.py:1206: error: Unsupported left operand type + # for <= ("Type[ExtensionOpsMixin]") [operator] + cls.__le__ = cls._create_comparison_method( # type: ignore[operator] + operator.le + ) + # pandas\core\arrays\base.py:1207: error: Unsupported left operand type + # for >= ("Type[ExtensionOpsMixin]") [operator] + cls.__ge__ = cls._create_comparison_method( # type: ignore[operator] + operator.ge + ) @classmethod def _create_logical_method(cls, op): @@ -1212,12 +1298,30 @@ def _create_logical_method(cls, op): @classmethod def _add_logical_ops(cls): - cls.__and__ = cls._create_logical_method(operator.and_) - cls.__rand__ = cls._create_logical_method(ops.rand_) - cls.__or__ = cls._create_logical_method(operator.or_) - cls.__ror__ = cls._create_logical_method(ops.ror_) - cls.__xor__ = cls._create_logical_method(operator.xor) - cls.__rxor__ = cls._create_logical_method(ops.rxor) + # pandas\core\arrays\base.py:1215: error: Unsupported left operand type + # for & ("Type[ExtensionOpsMixin]") [operator] + cls.__and__ = cls._create_logical_method( # type: ignore[operator] + operator.and_ + ) + # pandas\core\arrays\base.py:1216: error: "Type[ExtensionOpsMixin]" has + # no attribute "__rand__" [attr-defined] + cls.__rand__ = cls._create_logical_method( # type: ignore[attr-defined] + ops.rand_ + ) + # pandas\core\arrays\base.py:1217: error: Unsupported left operand type + # for | ("Type[ExtensionOpsMixin]") [operator] + cls.__or__ = cls._create_logical_method(operator.or_) # type: ignore[operator] + # pandas\core\arrays\base.py:1218: error: "Type[ExtensionOpsMixin]" has + # no attribute "__ror__" [attr-defined] + cls.__ror__ = cls._create_logical_method(ops.ror_) # type: ignore[attr-defined] + # pandas\core\arrays\base.py:1219: error: Unsupported left operand type + # for ^ ("Type[ExtensionOpsMixin]") + cls.__xor__ = cls._create_logical_method(operator.xor) # type: ignore[operator] + # pandas\core\arrays\base.py:1220: error: "Type[ExtensionOpsMixin]" has + # no attribute "__rxor__" + cls.__rxor__ = cls._create_logical_method( # type: ignore[attr-defined] + ops.rxor + ) class ExtensionScalarOpsMixin(ExtensionOpsMixin): diff --git a/setup.cfg b/setup.cfg index 12dc2aade3eec..3a25414246504 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.arrays.base] -check_untyped_defs=False - [mypy-pandas.core.arrays.datetimelike] check_untyped_defs=False From 9cd6c6916df5d83265f7c7b3a0d955c3177bf6ee Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 12:29:48 +0100 Subject: [PATCH 05/45] [mypy-pandas.core.arrays.datetimelike] --- pandas/core/arrays/datetimelike.py | 143 ++++++++++++++++++++++++----- setup.cfg | 3 - 2 files changed, 120 insertions(+), 26 deletions(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 8b6f49cc7d589..9edd6b3cf0b27 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -253,7 +253,11 @@ def strftime(self, date_format): 'March 10, 2018, 09:00:02 AM'], dtype='object') """ - result = self._format_native_types(date_format=date_format, na_rep=np.nan) + # pandas\core\arrays\datetimelike.py:256: error: "DatelikeOps" has no + # attribute "_format_native_types" [attr-defined] + result = self._format_native_types( # type: ignore[attr-defined] + date_format=date_format, na_rep=np.nan + ) return result.astype(object) @@ -367,19 +371,40 @@ class TimelikeOps: def _round(self, freq, mode, ambiguous, nonexistent): # round the local times - if is_datetime64tz_dtype(self.dtype): + + # pandas\core\arrays\datetimelike.py:370: error: "TimelikeOps" has no + # attribute "dtype" [attr-defined] + if is_datetime64tz_dtype(self.dtype): # type: ignore[attr-defined] # operate on naive timestamps, then convert back to aware - naive = self.tz_localize(None) + + # pandas\core\arrays\datetimelike.py:372: error: "TimelikeOps" has + # no attribute "tz_localize" [attr-defined] + naive = self.tz_localize(None) # type: ignore[attr-defined] result = naive._round(freq, mode, ambiguous, nonexistent) aware = result.tz_localize( - self.tz, ambiguous=ambiguous, nonexistent=nonexistent + # pandas\core\arrays\datetimelike.py:375: error: "TimelikeOps" + # has no attribute "tz" [attr-defined] + self.tz, # type: ignore[attr-defined] + ambiguous=ambiguous, + nonexistent=nonexistent, ) return aware - values = self.view("i8") + # pandas\core\arrays\datetimelike.py:379: error: "TimelikeOps" has no + # attribute "view" [attr-defined] + values = self.view("i8") # type: ignore[attr-defined] result = round_nsint64(values, mode, freq) - result = self._maybe_mask_results(result, fill_value=NaT) - return self._simple_new(result, dtype=self.dtype) + # pandas\core\arrays\datetimelike.py:381: error: "TimelikeOps" has no + # attribute "_maybe_mask_results" [attr-defined] + result = self._maybe_mask_results( # type: ignore[attr-defined] + result, fill_value=NaT + ) + # pandas\core\arrays\datetimelike.py:382: error: "TimelikeOps" has no + # attribute "_simple_new" [attr-defined] + + # pandas\core\arrays\datetimelike.py:382: error: "TimelikeOps" has no + # attribute "dtype" [attr-defined] + return self._simple_new(result, dtype=self.dtype) # type: ignore[attr-defined] @Appender((_round_doc + _round_example).format(op="round")) def round(self, freq, ambiguous="raise", nonexistent="raise"): @@ -409,16 +434,22 @@ def _with_freq(self, freq): if freq is None: # Always valid pass - elif len(self) == 0 and isinstance(freq, BaseOffset): + # pandas\core\arrays\datetimelike.py:412: error: Argument 1 to "len" + # has incompatible type "TimelikeOps"; expected "Sized" [arg-type] + elif len(self) == 0 and isinstance(freq, BaseOffset): # type: ignore[arg-type] # Always valid. In the TimedeltaArray case, we assume this # is a Tick offset. pass else: # As an internal method, we can ensure this assertion always holds assert freq == "infer" - freq = to_offset(self.inferred_freq) + # pandas\core\arrays\datetimelike.py:419: error: "TimelikeOps" has + # no attribute "inferred_freq" [attr-defined] + freq = to_offset(self.inferred_freq) # type: ignore[attr-defined] - arr = self.view() + # pandas\core\arrays\datetimelike.py:421: error: "TimelikeOps" has no + # attribute "view" [attr-defined] + arr = self.view() # type: ignore[attr-defined] arr._freq = freq return arr @@ -629,7 +660,12 @@ def astype(self, dtype, copy=True): def view(self, dtype=None): if dtype is None or dtype is self.dtype: - return type(self)(self._ndarray, dtype=self.dtype) + # pandas\core\arrays\datetimelike.py:632: error: Too many arguments for + # "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\arrays\datetimelike.py:632: error: Unexpected keyword + # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] + return type(self)(self._ndarray, dtype=self.dtype) # type: ignore[call-arg] return self._ndarray.view(dtype=dtype) # ------------------------------------------------------------------ @@ -668,7 +704,12 @@ def _values_for_factorize(self): @classmethod def _from_factorized(cls, values, original): - return cls(values, dtype=original.dtype) + # pandas\core\arrays\datetimelike.py:671: error: Too many arguments for + # "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\arrays\datetimelike.py:671: error: Unexpected keyword + # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] + return cls(values, dtype=original.dtype) # type: ignore[call-arg] # ------------------------------------------------------------------ # Validation Methods @@ -743,14 +784,23 @@ def _validate_shift_value(self, fill_value): if is_valid_nat_for_dtype(fill_value, self.dtype): fill_value = NaT elif isinstance(fill_value, self._recognized_scalars): - fill_value = self._scalar_type(fill_value) + # pandas\core\arrays\datetimelike.py:746: error: Too many arguments + # for "object" [call-arg] + fill_value = self._scalar_type(fill_value) # type: ignore[call-arg] else: # only warn if we're not going to raise if self._scalar_type is Period and lib.is_integer(fill_value): # kludge for #31971 since Period(integer) tries to cast to str - new_fill = Period._from_ordinal(fill_value, freq=self.dtype.freq) + + # pandas\core\arrays\datetimelike.py:751: error: + # "ExtensionDtype" has no attribute "freq" [attr-defined] + new_fill = Period._from_ordinal( + fill_value, freq=self.dtype.freq # type: ignore[attr-defined] + ) else: - new_fill = self._scalar_type(fill_value) + # pandas\core\arrays\datetimelike.py:753: error: Too many + # arguments for "object" [call-arg] + new_fill = self._scalar_type(fill_value) # type: ignore[call-arg] # stacklevel here is chosen to be correct when called from # DataFrame.shift or Series.shift @@ -927,8 +977,14 @@ def value_counts(self, dropna=False): cls = type(self) result = value_counts(values, sort=False, dropna=dropna) + # pandas\core\arrays\datetimelike.py:931: error: Too many arguments + # for "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\arrays\datetimelike.py:931: error: Unexpected keyword + # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] index = Index( - cls(result.index.view("i8"), dtype=self.dtype), name=result.index.name + cls(result.index.view("i8"), dtype=self.dtype), # type: ignore[call-arg] + name=result.index.name, ) return Series(result._values, index=index, name=result.name) @@ -1062,7 +1118,10 @@ def _validate_frequency(cls, index, freq, **kwargs): return None try: - on_freq = cls._generate_range( + # pandas\core\arrays\datetimelike.py:1065: error: + # "Type[DatetimeLikeArrayMixin]" has no attribute "_generate_range" + # [attr-defined] + on_freq = cls._generate_range( # type: ignore[attr-defined] start=index[0], end=None, periods=len(index), freq=freq, **kwargs ) if not np.array_equal(index.asi8, on_freq.asi8): @@ -1152,7 +1211,13 @@ def _add_timedeltalike_scalar(self, other): # i.e np.timedelta64("NaT"), not recognized by delta_to_nanoseconds new_values = np.empty(self.shape, dtype="i8") new_values[:] = iNaT - return type(self)(new_values, dtype=self.dtype) + + # pandas\core\arrays\datetimelike.py:1155: error: Too many + # arguments for "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\arrays\datetimelike.py:1155: error: Unexpected + # keyword argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] + return type(self)(new_values, dtype=self.dtype) # type: ignore[call-arg] inc = delta_to_nanoseconds(other) new_values = checked_add_with_arr(self.asi8, inc, arr_mask=self._isnan).view( @@ -1165,7 +1230,17 @@ def _add_timedeltalike_scalar(self, other): # adding a scalar preserves freq new_freq = self.freq - return type(self)(new_values, dtype=self.dtype, freq=new_freq) + # pandas\core\arrays\datetimelike.py:1168: error: Too many arguments + # for "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\arrays\datetimelike.py:1168: error: Unexpected keyword + # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\arrays\datetimelike.py:1168: error: Unexpected keyword + # argument "freq" for "DatetimeLikeArrayMixin" [call-arg] + return type(self)( # type: ignore[call-arg] + new_values, dtype=self.dtype, freq=new_freq + ) def _add_timedelta_arraylike(self, other): """ @@ -1195,7 +1270,12 @@ def _add_timedelta_arraylike(self, other): mask = (self._isnan) | (other._isnan) new_values[mask] = iNaT - return type(self)(new_values, dtype=self.dtype) + # pandas\core\arrays\datetimelike.py:1198: error: Too many arguments + # for "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\arrays\datetimelike.py:1198: error: Unexpected keyword + # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] + return type(self)(new_values, dtype=self.dtype) # type: ignore[call-arg] def _add_nat(self): """ @@ -1210,7 +1290,16 @@ def _add_nat(self): # and datetime dtypes result = np.zeros(self.shape, dtype=np.int64) result.fill(iNaT) - return type(self)(result, dtype=self.dtype, freq=None) + + # pandas\core\arrays\datetimelike.py:1213: error: Too many arguments + # for "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\arrays\datetimelike.py:1213: error: Unexpected keyword + # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\arrays\datetimelike.py:1213: error: Unexpected keyword + # argument "freq" for "DatetimeLikeArrayMixin" [call-arg] + return type(self)(result, dtype=self.dtype, freq=None) # type: ignore[call-arg] def _sub_nat(self): """ @@ -1300,7 +1389,13 @@ def _time_shift(self, periods, freq=None): # Note: in the DatetimeTZ case, _generate_range will infer the # appropriate timezone from `start` and `end`, so tz does not need # to be passed explicitly. - return self._generate_range(start=start, end=end, periods=None, freq=self.freq) + + # pandas\core\arrays\datetimelike.py:1303: error: + # "DatetimeLikeArrayMixin" has no attribute "_generate_range" + # [attr-defined] + return self._generate_range( # type: ignore[attr-defined] + start=start, end=end, periods=None, freq=self.freq + ) @unpack_zerodim_and_defer("__add__") def __add__(self, other): @@ -1438,7 +1533,9 @@ def __rsub__(self, other): # TODO: Can we simplify/generalize these cases at all? raise TypeError(f"cannot subtract {type(self).__name__} from {other.dtype}") elif is_timedelta64_dtype(self.dtype): - return (-self) + other + # pandas\core\arrays\datetimelike.py:1441: error: Unsupported + # operand type for unary - ("DatetimeLikeArrayMixin") [operator] + return (-self) + other # type: ignore[operator] # We get here with e.g. datetime objects return -(self - other) diff --git a/setup.cfg b/setup.cfg index 3a25414246504..9abb06eef0ffa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.arrays.datetimelike] -check_untyped_defs=False - [mypy-pandas.core.arrays.sparse.array] check_untyped_defs=False From f3f3103cb0eced6b4f965ac4006f0d646cae62b9 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 12:44:49 +0100 Subject: [PATCH 06/45] [mypy-pandas.core.arrays.sparse.array] --- pandas/core/arrays/sparse/array.py | 37 ++++++++++++++++++++++++------ setup.cfg | 3 --- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index d4ec641794fc2..f419f80674e14 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -796,7 +796,10 @@ def __getitem__(self, key): key = check_array_indexer(self, key) if com.is_bool_indexer(key): - key = check_bool_indexer(self, key) + # pandas\core\arrays\sparse\array.py:799: error: Argument 1 to + # "check_bool_indexer" has incompatible type "SparseArray"; + # expected "Index" [arg-type] + key = check_bool_indexer(self, key) # type: ignore return self.take(np.arange(len(key), dtype=np.int32)[key]) elif hasattr(key, "__len__"): @@ -1484,15 +1487,35 @@ def cmp_method(self, other): @classmethod def _add_unary_ops(cls): - cls.__pos__ = cls._create_unary_method(operator.pos) - cls.__neg__ = cls._create_unary_method(operator.neg) - cls.__invert__ = cls._create_unary_method(operator.invert) + # pandas\core\arrays\sparse\array.py:1487: error: Unsupported operand + # type for unary + ("Type[SparseArray]") [operator] + cls.__pos__ = cls._create_unary_method(operator.pos) # type: ignore[operator] + # pandas\core\arrays\sparse\array.py:1488: error: Unsupported operand + # type for unary - ("Type[SparseArray]") [operator] + cls.__neg__ = cls._create_unary_method(operator.neg) # type: ignore[operator] + # pandas\core\arrays\sparse\array.py:1489: error: Unsupported operand + # type for ~ ("Type[SparseArray]") [operator] + cls.__invert__ = cls._create_unary_method( # type: ignore[operator] + operator.invert + ) @classmethod def _add_comparison_ops(cls): - cls.__and__ = cls._create_comparison_method(operator.and_) - cls.__or__ = cls._create_comparison_method(operator.or_) - cls.__xor__ = cls._create_arithmetic_method(operator.xor) + # pandas\core\arrays\sparse\array.py:1493: error: Unsupported left + # operand type for & ("Type[SparseArray]") [operator] + cls.__and__ = cls._create_comparison_method( # type: ignore[operator] + operator.and_ + ) + # pandas\core\arrays\sparse\array.py:1494: error: Unsupported left + # operand type for | ("Type[SparseArray]") [operator] + cls.__or__ = cls._create_comparison_method( # type: ignore[operator] + operator.or_ + ) + # pandas\core\arrays\sparse\array.py:1495: error: Unsupported left + # operand type for ^ ("Type[SparseArray]") [operator] + cls.__xor__ = cls._create_arithmetic_method( # type: ignore[operator] + operator.xor + ) super()._add_comparison_ops() # ---------- diff --git a/setup.cfg b/setup.cfg index 9abb06eef0ffa..5a28769386fdc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.arrays.sparse.array] -check_untyped_defs=False - [mypy-pandas.core.arrays.string_] check_untyped_defs=False From ec0fd6ca4d66c97597540e6ef5638f6788d64bd6 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 12:57:49 +0100 Subject: [PATCH 07/45] [mypy-pandas.core.arrays.string_] --- pandas/core/arrays/string_.py | 5 ++++- setup.cfg | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/string_.py b/pandas/core/arrays/string_.py index 9ea34d4680748..cd6d52a1ae7ff 100644 --- a/pandas/core/arrays/string_.py +++ b/pandas/core/arrays/string_.py @@ -185,7 +185,10 @@ def __init__(self, values, copy=False): values = extract_array(values) super().__init__(values, copy=copy) - self._dtype = StringDtype() + # pandas\core\arrays\string_.py:188: error: Incompatible types in + # assignment (expression has type "StringDtype", variable has type + # "PandasDtype") [assignment] + self._dtype = StringDtype() # type: ignore[assignment] if not isinstance(values, type(self)): self._validate() diff --git a/setup.cfg b/setup.cfg index 5a28769386fdc..f84776cc5c70a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.arrays.string_] -check_untyped_defs=False - [mypy-pandas.core.base] check_untyped_defs=False From 4eecd562a71acd01afc171e36367d86b75047995 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 13:43:13 +0100 Subject: [PATCH 08/45] [mypy-pandas.core.base] --- pandas/core/base.py | 104 +++++++++++++++++++++++++++++++++++--------- setup.cfg | 3 -- 2 files changed, 84 insertions(+), 23 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 9e6f93b656af8..5be9da9942957 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -81,7 +81,9 @@ def __sizeof__(self): either a value or Series of values """ if hasattr(self, "memory_usage"): - mem = self.memory_usage(deep=True) + # pandas\core\base.py:84: error: "PandasObject" has no attribute + # "memory_usage" [attr-defined] + mem = self.memory_usage(deep=True) # type: ignore[attr-defined] return int(mem if is_scalar(mem) else mem.sum()) # no memory_usage attribute, so fall back to object's 'sizeof' @@ -191,7 +193,9 @@ def _selection_list(self): @cache_readonly def _selected_obj(self): if self._selection is None or isinstance(self.obj, ABCSeries): - return self.obj + # pandas\core\base.py:194: error: "SelectionMixin" has no attribute + # "obj" [attr-defined] + return self.obj # type: ignore[attr-defined] else: return self.obj[self._selection] @@ -204,18 +208,35 @@ def _obj_with_exclusions(self): if self._selection is not None and isinstance(self.obj, ABCDataFrame): return self.obj.reindex(columns=self._selection_list) - if len(self.exclusions) > 0: - return self.obj.drop(self.exclusions, axis=1) + # pandas\core\base.py:207: error: "SelectionMixin" has no attribute + # "exclusions" [attr-defined] + if len(self.exclusions) > 0: # type: ignore[attr-defined] + # pandas\core\base.py:208: error: "SelectionMixin" has no attribute + # "obj" [attr-defined] + + # pandas\core\base.py:208: error: "SelectionMixin" has no attribute + # "exclusions" [attr-defined] + return self.obj.drop(self.exclusions, axis=1) # type: ignore[attr-defined] else: - return self.obj + # pandas\core\base.py:210: error: "SelectionMixin" has no attribute + # "obj" [attr-defined] + return self.obj # type: ignore[attr-defined] def __getitem__(self, key): if self._selection is not None: raise IndexError(f"Column(s) {self._selection} already selected") if isinstance(key, (list, tuple, ABCSeries, ABCIndexClass, np.ndarray)): - if len(self.obj.columns.intersection(key)) != len(key): - bad_keys = list(set(key).difference(self.obj.columns)) + # pandas\core\base.py:217: error: "SelectionMixin" has no attribute + # "obj" [attr-defined] + if len( + self.obj.columns.intersection(key) # type: ignore[attr-defined] + ) != len(key): + # pandas\core\base.py:218: error: "SelectionMixin" has no + # attribute "obj" [attr-defined] + bad_keys = list(set(key).difference( + self.obj.columns # type: ignore[attr-defined] + )) raise KeyError(f"Columns not found: {str(bad_keys)[1:-1]}") return self._gotitem(list(key), ndim=2) @@ -566,7 +587,11 @@ def _aggregate_multiple_funcs(self, arg, _axis): from pandas import Series - result = Series(results, index=keys, name=self.name) + # pandas\core\base.py:569: error: "SelectionMixin" has no attribute + # "name" [attr-defined] + result = Series( + results, index=keys, name=self.name # type: ignore[attr-defined] + ) if is_nested_object(result): raise ValueError( "cannot combine transform and aggregation operations" @@ -833,8 +858,13 @@ def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default, **kwargs): array(['1999-12-31T23:00:00.000000000', '2000-01-01T23:00:00...'], dtype='datetime64[ns]') """ - if is_extension_array_dtype(self.dtype): - return self.array.to_numpy(dtype, copy=copy, na_value=na_value, **kwargs) + # pandas\core\base.py:836: error: "IndexOpsMixin" has no attribute + # "dtype" [attr-defined] + if is_extension_array_dtype(self.dtype): # type: ignore[attr-defined] + # pandas\core\base.py:837: error: Too many arguments for "to_numpy" + # of "ExtensionArray" [call-arg] + return self.array.to_numpy( # type: ignore[call-arg] + dtype, copy=copy, na_value=na_value, **kwargs) elif kwargs: bad_keys = list(kwargs.keys())[0] raise TypeError( @@ -846,7 +876,9 @@ def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default, **kwargs): if copy or na_value is not lib.no_default: result = result.copy() if na_value is not lib.no_default: - result[self.isna()] = na_value + # pandas\core\base.py:849: error: "IndexOpsMixin" has no + # attribute "isna" [attr-defined] + result[self.isna()] = na_value # type: ignore[attr-defined] return result @property @@ -1119,10 +1151,17 @@ def _map_values(self, mapper, na_action=None): if isinstance(mapper, ABCSeries): # Since values were input this means we came from either # a dict or a series and mapper should be an index - if is_categorical_dtype(self.dtype): + + # pandas\core\base.py:1122: error: "IndexOpsMixin" has no attribute + # "dtype" [attr-defined] + if is_categorical_dtype(self.dtype): # type: ignore[attr-defined] # use the built in categorical series mapper which saves # time by mapping the categories instead of all values - return self._values.map(mapper) + + # pandas\core\base.py:1125: error: Item "ExtensionArray" of + # "Union[ExtensionArray, Any]" has no attribute "map" + # [union-attr] + return self._values.map(mapper) # type: ignore[union-attr] values = self._values @@ -1132,14 +1171,21 @@ def _map_values(self, mapper, na_action=None): return new_values # we must convert to python types - if is_extension_array_dtype(self.dtype) and hasattr(self._values, "map"): + + # pandas\core\base.py:1135: error: "IndexOpsMixin" has no attribute + # "dtype" [attr-defined] + if is_extension_array_dtype( + self.dtype # type: ignore[attr-defined] + ) and hasattr(self._values, "map"): # GH#23179 some EAs do not have `map` values = self._values if na_action is not None: raise NotImplementedError map_f = lambda values, f: values.map(f) else: - values = self.astype(object)._values + # pandas\core\base.py:1142: error: "IndexOpsMixin" has no attribute + # "astype" [attr-defined] + values = self.astype(object)._values # type: ignore[attr-defined] if na_action == "ignore": def map_f(values, f): @@ -1255,7 +1301,16 @@ def unique(self): if not isinstance(values, np.ndarray): result = values.unique() - if self.dtype.kind in ["m", "M"] and isinstance(self, ABCSeries): + # pandas\core\base.py:1258: error: "IndexOpsMixin" has no attribute + # "dtype" [attr-defined] + if ( + self.dtype.kind # type: ignore[attr-defined] + in [ + "m", + "M" + ] + and isinstance(self, ABCSeries) + ): # GH#31182 Series._values returns EA, unpack for backward-compat if getattr(self.dtype, "tz", None) is None: result = np.asarray(result) @@ -1376,7 +1431,9 @@ def memory_usage(self, deep=False): are not components of the array if deep=False or if used on PyPy """ if hasattr(self.array, "memory_usage"): - return self.array.memory_usage(deep=deep) + # pandas\core\base.py:1379: error: "ExtensionArray" has no + # attribute "memory_usage" [attr-defined] + return self.array.memory_usage(deep=deep) # type: ignore[attr-defined] v = self.array.nbytes if deep and is_object_dtype(self) and not PYPY: @@ -1504,7 +1561,9 @@ def drop_duplicates(self, keep="first"): return self._shallow_copy() duplicated = self.duplicated(keep=keep) - result = self[np.logical_not(duplicated)] + # pandas\core\base.py:1507: error: Value of type "IndexOpsMixin" is not + # indexable [index] + result = self[np.logical_not(duplicated)] # type: ignore[index] return result def duplicated(self, keep="first"): @@ -1513,6 +1572,11 @@ def duplicated(self, keep="first"): return np.zeros(len(self), dtype=bool) return duplicated(self, keep=keep) else: - return self._constructor( - duplicated(self, keep=keep), index=self.index + # pandas\core\base.py:1516: error: "IndexOpsMixin" has no attribute + # "_constructor" [attr-defined] + return self._constructor( # type: ignore[attr-defined] + duplicated(self, keep=keep), + # pandas\core\base.py:1517: error: "IndexOpsMixin" has no attribute + # "index" [attr-defined] + index=self.index, # type: ignore[attr-defined] ).__finalize__(self, method="duplicated") diff --git a/setup.cfg b/setup.cfg index f84776cc5c70a..78de6c4091fa5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.base] -check_untyped_defs=False - [mypy-pandas.core.computation.expr] check_untyped_defs=False From e9a3905b27756ab2a878f8a66fd9147500a7e35c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 13:48:45 +0100 Subject: [PATCH 09/45] black fixup --- pandas/core/base.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 5be9da9942957..84426a3cd23b3 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -234,9 +234,9 @@ def __getitem__(self, key): ) != len(key): # pandas\core\base.py:218: error: "SelectionMixin" has no # attribute "obj" [attr-defined] - bad_keys = list(set(key).difference( - self.obj.columns # type: ignore[attr-defined] - )) + bad_keys = list( + set(key).difference(self.obj.columns) # type: ignore[attr-defined] + ) raise KeyError(f"Columns not found: {str(bad_keys)[1:-1]}") return self._gotitem(list(key), ndim=2) @@ -864,7 +864,8 @@ def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default, **kwargs): # pandas\core\base.py:837: error: Too many arguments for "to_numpy" # of "ExtensionArray" [call-arg] return self.array.to_numpy( # type: ignore[call-arg] - dtype, copy=copy, na_value=na_value, **kwargs) + dtype, copy=copy, na_value=na_value, **kwargs + ) elif kwargs: bad_keys = list(kwargs.keys())[0] raise TypeError( @@ -1307,7 +1308,7 @@ def unique(self): self.dtype.kind # type: ignore[attr-defined] in [ "m", - "M" + "M", ] and isinstance(self, ABCSeries) ): From 7d13f9b77f0f6c467019a5e3e5821da495138f70 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 13:59:23 +0100 Subject: [PATCH 10/45] [mypy-pandas.core.computation.expr] --- pandas/core/computation/expr.py | 10 ++++++++-- setup.cfg | 3 --- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index 8c56f02c8d3cc..d2d4106931b8e 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -660,7 +660,10 @@ def visit_Call(self, node, side=None, **kwargs): raise if res is None: - raise ValueError(f"Invalid function call {node.func.id}") + # pandas\core\computation\expr.py:663: error: "expr" has no + # attribute "id" [attr-defined] + tmp = node.func.id # type: ignore[attr-defined] + raise ValueError(f"Invalid function call {tmp}") if hasattr(res, "value"): res = res.value @@ -681,7 +684,10 @@ def visit_Call(self, node, side=None, **kwargs): for key in node.keywords: if not isinstance(key, ast.keyword): - raise ValueError(f"keyword error in function call '{node.func.id}'") + # pandas\core\computation\expr.py:684: error: "expr" has no + # attribute "id" [attr-defined] + tmp = node.func.id # type: ignore[attr-defined] + raise ValueError(f"keyword error in function call '{tmp}'") if key.arg: kwargs[key.arg] = self.visit(key.value).value diff --git a/setup.cfg b/setup.cfg index 78de6c4091fa5..2d8697ea50083 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.computation.expr] -check_untyped_defs=False - [mypy-pandas.core.computation.expressions] check_untyped_defs=False From 2684e52031421bd83ad09b9b4949b81227507cd6 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 14:12:10 +0100 Subject: [PATCH 11/45] [mypy-pandas.core.computation.expressions] --- pandas/core/computation/expressions.py | 7 ++++++- setup.cfg | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/core/computation/expressions.py b/pandas/core/computation/expressions.py index 5bfd2e93a9247..0ebdef561c10b 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -248,7 +248,12 @@ def where(cond, a, b, use_numexpr=True): use_numexpr : bool, default True Whether to try to use numexpr. """ - return _where(cond, a, b) if use_numexpr else _where_standard(cond, a, b) + # pandas\core\computation\expressions.py:251: error: "None" not callable [misc] + return ( + _where(cond, a, b) # type: ignore[misc] + if use_numexpr + else _where_standard(cond, a, b) + ) def set_test_mode(v: bool = True) -> None: diff --git a/setup.cfg b/setup.cfg index 2d8697ea50083..7fee4ee7e4e69 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.computation.expressions] -check_untyped_defs=False - [mypy-pandas.core.computation.ops] check_untyped_defs=False From cf4bc0a95cf4bfcc62ee1cdaa25f4c6cd1ac0c39 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 14:28:07 +0100 Subject: [PATCH 12/45] [mypy-pandas.core.computation.ops] --- pandas/core/computation/ops.py | 7 +++++-- setup.cfg | 3 --- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/computation/ops.py b/pandas/core/computation/ops.py index 5759cd17476d6..74bee80c6c8a6 100644 --- a/pandas/core/computation/ops.py +++ b/pandas/core/computation/ops.py @@ -69,7 +69,9 @@ def __init__(self, name: str, is_local: Optional[bool] = None): class Term: def __new__(cls, name, env, side=None, encoding=None): klass = Constant if not isinstance(name, str) else cls - supr_new = super(Term, klass).__new__ + # pandas\core\computation\ops.py:72: error: Argument 2 for "super" not + # an instance of argument 1 [misc] + supr_new = super(Term, klass).__new__ # type: ignore[misc] return supr_new(klass) is_local: bool @@ -589,7 +591,8 @@ def __init__(self, func, args): self.func = func def __call__(self, env): - operands = [op(env) for op in self.operands] + # pandas\core\computation\ops.py:592: error: "Op" not callable [operator] + operands = [op(env) for op in self.operands] # type: ignore[operator] with np.errstate(all="ignore"): return self.func.func(*operands) diff --git a/setup.cfg b/setup.cfg index 7fee4ee7e4e69..8eebfc35ffb12 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.computation.ops] -check_untyped_defs=False - [mypy-pandas.core.computation.pytables] check_untyped_defs=False From c3bd8970a50016d4a70f969df082ac52d2d36bdc Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 14:46:09 +0100 Subject: [PATCH 13/45] [mypy-pandas.core.computation.pytables] --- pandas/core/computation/pytables.py | 34 ++++++++++++++++++++++++----- setup.cfg | 3 --- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index d876c655421ef..f85826e467dc5 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -43,7 +43,10 @@ class Term(ops.Term): def __new__(cls, name, env, side=None, encoding=None): klass = Constant if not isinstance(name, str) else cls - return object.__new__(klass) + # pandas\core\computation\pytables.py:46: error: Argument 1 to + # "__new__" of "object" has incompatible type "object"; expected + # "Type[object]" [arg-type] + return object.__new__(klass) # type: ignore[arg-type] def __init__(self, name, env: PyTablesScope, side=None, encoding=None): super().__init__(name, env, side=side, encoding=encoding) @@ -186,7 +189,12 @@ def stringify(value): if self.encoding is not None: encoder = partial(pprint_thing_encoded, encoding=self.encoding) else: - encoder = pprint_thing + # pandas\core\computation\pytables.py:189: error: Incompatible + # types in assignment (expression has type "Callable[[Any, int, + # Union[Mapping[str, str], Iterable[str], None], bool, bool, + # Optional[int]], str]", variable has type "partial[bytes]") + # [assignment] + encoder = pprint_thing # type: ignore[assignment] return encoder(value) kind = ensure_decoded(self.kind) @@ -259,7 +267,11 @@ def invert(self): if self.filter is not None: f = list(self.filter) f[1] = self.generate_filter_op(invert=True) - self.filter = tuple(f) + # pandas\core\computation\pytables.py:262: error: Incompatible + # types in assignment (expression has type "Tuple[Any, ...]", + # variable has type "Optional[Tuple[Any, Any, Index]]") + # [assignment] + self.filter = tuple(f) # type: ignore[assignment] return self def format(self): @@ -348,20 +360,30 @@ def evaluate(self): # too many values to create the expression? if len(values) <= self._max_selectors: vs = [self.generate(v) for v in values] - self.condition = f"({' | '.join(vs)})" + # pandas\core\computation\pytables.py:351: error: Incompatible + # types in assignment (expression has type "str", variable has + # type "None") [assignment] + self.condition = f"({' | '.join(vs)})" # type: ignore[assignment] # use a filter after reading else: return None else: - self.condition = self.generate(values[0]) + # pandas\core\computation\pytables.py:357: error: Incompatible + # types in assignment (expression has type "str", variable has type + # "None") [assignment] + self.condition = self.generate(values[0]) # type: ignore[assignment] return self class JointConditionBinOp(ConditionBinOp): def evaluate(self): - self.condition = f"({self.lhs.condition} {self.op} {self.rhs.condition})" + # pandas\core\computation\pytables.py:364: error: Incompatible types in + # assignment (expression has type "str", variable has type "None") + # [assignment] + tmp = f"({self.lhs.condition} {self.op} {self.rhs.condition})" + self.condition = tmp # type: ignore[assignment] return self diff --git a/setup.cfg b/setup.cfg index 8eebfc35ffb12..f726275a26448 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.computation.pytables] -check_untyped_defs=False - [mypy-pandas.core.computation.scope] check_untyped_defs=False From b97ca7b9c7d3c28a36362a884341df5df4410f77 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 15:05:51 +0100 Subject: [PATCH 14/45] [mypy-pandas.core.computation.scope] --- pandas/core/computation/scope.py | 41 +++++++++++++++++++++++++++----- setup.cfg | 3 --- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/pandas/core/computation/scope.py b/pandas/core/computation/scope.py index 2925f583bfc56..18c16d396e68a 100644 --- a/pandas/core/computation/scope.py +++ b/pandas/core/computation/scope.py @@ -129,15 +129,27 @@ def __init__( # shallow copy here because we don't want to replace what's in # scope when we align terms (alignment accesses the underlying # numpy array of pandas objects) - self.scope = self.scope.new_child((global_dict or frame.f_globals).copy()) + + # pandas\core\computation\scope.py:132: error: Incompatible types + # in assignment (expression has type "ChainMap[str, Any]", variable + # has type "DeepChainMap[str, Any]") [assignment] + tmp = self.scope.new_child((global_dict or frame.f_globals).copy()) + self.scope = tmp # type: ignore[assignment] if not isinstance(local_dict, Scope): - self.scope = self.scope.new_child((local_dict or frame.f_locals).copy()) + # pandas\core\computation\scope.py:134: error: Incompatible + # types in assignment (expression has type "ChainMap[str, + # Any]", variable has type "DeepChainMap[str, Any]") + # [assignment] + tmp = self.scope.new_child((local_dict or frame.f_locals).copy()) + self.scope = tmp # type: ignore[assignment] finally: del frame # assumes that resolvers are going from outermost scope to inner if isinstance(local_dict, Scope): - resolvers += tuple(local_dict.resolvers.maps) + # pandas\core\computation\scope.py:140: error: Cannot determine + # type of 'resolvers' [has-type] + resolvers += tuple(local_dict.resolvers.maps) # type: ignore[has-type] self.resolvers = DeepChainMap(*resolvers) self.temps = {} @@ -225,7 +237,9 @@ def swapkey(self, old_key: str, new_key: str, new_value=None): for mapping in maps: if old_key in mapping: - mapping[new_key] = new_value + # pandas\core\computation\scope.py:228: error: Unsupported + # target for indexed assignment ("Mapping[Any, Any]") [index] + mapping[new_key] = new_value # type: ignore[index] return def _get_vars(self, stack, scopes: List[str]): @@ -244,7 +258,11 @@ def _get_vars(self, stack, scopes: List[str]): for scope, (frame, _, _, _, _, _) in variables: try: d = getattr(frame, "f_" + scope) - self.scope = self.scope.new_child(d) + # pandas\core\computation\scope.py:247: error: Incompatible + # types in assignment (expression has type "ChainMap[str, + # Any]", variable has type "DeepChainMap[str, Any]") + # [assignment] + self.scope = self.scope.new_child(d) # type: ignore[assignment] finally: # won't remove it, but DECREF it # in Py3 this probably isn't necessary since frame won't be @@ -311,5 +329,16 @@ def full_scope(self): vars : DeepChainMap All variables in this scope. """ - maps = [self.temps] + self.resolvers.maps + self.scope.maps + # pandas\core\computation\scope.py:314: error: Unsupported operand + # types for + ("List[Dict[Any, Any]]" and "List[Mapping[Any, Any]]") + # [operator] + + # pandas\core\computation\scope.py:314: error: Unsupported operand + # types for + ("List[Dict[Any, Any]]" and "List[Mapping[str, Any]]") + # [operator] + maps = ( + [self.temps] + + self.resolvers.maps # type: ignore[operator] + + self.scope.maps # type: ignore[operator] + ) return DeepChainMap(*maps) diff --git a/setup.cfg b/setup.cfg index f726275a26448..f8dcb4b0c3aa3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.computation.scope] -check_untyped_defs=False - [mypy-pandas.core.frame] check_untyped_defs=False From da41a72967b136c11e40b2a41f2ab6aef99d5d13 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 15:18:52 +0100 Subject: [PATCH 15/45] [mypy-pandas.core.frame] --- pandas/core/frame.py | 20 +++++++++++++++++--- setup.cfg | 3 --- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1f9987d9d3f5b..c284cc4252896 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4851,7 +4851,15 @@ def _maybe_casted_values(index, labels=None): values, _ = maybe_upcast_putmask(values, mask, np.nan) if issubclass(values_type, DatetimeLikeArray): - values = values_type(values, dtype=values_dtype) + # pandas\core\frame.py:4854: error: Too many arguments + # for "DatetimeLikeArrayMixin" [call-arg] + + # pandas\core\frame.py:4854: error: Unexpected keyword + # argument "dtype" for "DatetimeLikeArrayMixin" + # [call-arg] + values = values_type( + values, dtype=values_dtype # type: ignore[call-arg] + ) return values @@ -7376,7 +7384,11 @@ def aggregate(self, func=None, axis=0, *args, **kwargs): result = None try: - result, how = self._aggregate(func, axis=axis, *args, **kwargs) + # pandas\core\frame.py:7379: error: "_aggregate" gets multiple + # values for keyword argument "axis" [misc] + result, how = self._aggregate( # type: ignore[misc] + func, axis=axis, *args, **kwargs + ) except TypeError as err: exc = TypeError( "DataFrame constructor called with " @@ -9277,7 +9289,9 @@ def _AXIS_NAMES(self) -> Dict[int, str]: def _from_nested_dict(data): - new_data = collections.defaultdict(dict) + # pandas\core\frame.py:9280: error: Need type annotation for 'new_data' + # [var-annotated] + new_data = collections.defaultdict(dict) # type: ignore[var-annotated] for index, s in data.items(): for col, v in s.items(): new_data[col][index] = v diff --git a/setup.cfg b/setup.cfg index f8dcb4b0c3aa3..199cb95b75b03 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.frame] -check_untyped_defs=False - [mypy-pandas.core.generic] check_untyped_defs=False From 4a1cdeaecd82f49bf2537215bed62714818bd0f2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 16:09:23 +0100 Subject: [PATCH 16/45] [mypy-pandas.core.generic] --- pandas/core/generic.py | 131 +++++++++++++++++++++++++++++++++-------- setup.cfg | 3 - 2 files changed, 105 insertions(+), 29 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 04e1fc91c5fd4..df50a3b9d38e8 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1996,7 +1996,11 @@ def _repr_data_resource_(self): if config.get_option("display.html.table_schema"): data = self.head(config.get_option("display.max_rows")) payload = json.loads( - data.to_json(orient="table"), object_pairs_hook=collections.OrderedDict + # pandas\core\generic.py:1999: error: Argument 1 to "loads" has + # incompatible type "Optional[str]"; expected "Union[str, + # bytes, bytearray]" [arg-type] + data.to_json(orient="table"), # type: ignore[arg-type] + object_pairs_hook=collections.OrderedDict, ) return payload @@ -3113,7 +3117,10 @@ def to_latex( multirow = config.get_option("display.latex.multirow") formatter = DataFrameFormatter( - self, + # pandas\core\generic.py:3116: error: Argument 1 to + # "DataFrameFormatter" has incompatible type "NDFrame"; expected + # "DataFrame" [arg-type] + self, # type: ignore[arg-type] columns=columns, col_space=col_space, na_rep=na_rep, @@ -3829,7 +3836,12 @@ def _check_setitem_copy(self, stacklevel=4, t="setting", force=False): # the copy weakref if self._is_copy is not None and not isinstance(self._is_copy, str): r = self._is_copy() - if not gc.get_referents(r) or r.shape == self.shape: + # pandas\core\generic.py:3832: error: Item "None" of + # "Optional[Any]" has no attribute "shape" [union-attr] + if ( + not gc.get_referents(r) + or r.shape == self.shape # type: ignore[union-attr] + ): self._is_copy = None return @@ -7258,9 +7270,23 @@ def asof(self, where, subset=None): nulls = self.isna() if is_series else self[subset].isna().any(1) if nulls.all(): if is_series: - return self._constructor(np.nan, index=where, name=self.name) + # pandas\core\generic.py:7261: error: Unexpected keyword + # argument "index" for "NDFrame" [call-arg] + + # pandas\core\generic.py:7261: error: Unexpected keyword + # argument "name" for "NDFrame" [call-arg] + return self._constructor( + np.nan, index=where, name=self.name # type: ignore[call-arg] + ) elif is_list: - return self._constructor(np.nan, index=where, columns=self.columns) + # pandas\core\generic.py:7263: error: Unexpected keyword + # argument "index" for "NDFrame" [call-arg] + + # pandas\core\generic.py:7263: error: Unexpected keyword + # argument "columns" for "NDFrame" [call-arg] + return self._constructor( + np.nan, index=where, columns=self.columns # type: ignore[call-arg] + ) else: return self._constructor_sliced( np.nan, index=self.columns, name=where[0] @@ -10399,7 +10425,9 @@ def _add_numeric_operations(cls): """ axis_descr, name1, name2 = _doc_parms(cls) - cls.any = _make_logical_function( + # pandas\core\generic.py:10402: error: "Type[NDFrame]" has no attribute + # "any" [attr-defined] + cls.any = _make_logical_function( # type: ignore[attr-defined] cls, "any", name1=name1, @@ -10411,7 +10439,9 @@ def _add_numeric_operations(cls): examples=_any_examples, empty_value=False, ) - cls.all = _make_logical_function( + # pandas\core\generic.py:10414: error: "Type[NDFrame]" has no attribute + # "all" [attr-defined] + cls.all = _make_logical_function( # type: ignore[attr-defined] cls, "all", name1=name1, @@ -10467,9 +10497,13 @@ def mad(self, axis=None, skipna=None, level=None): demeaned = data.sub(data.mean(axis=1), axis=0) return np.abs(demeaned).mean(axis=axis, skipna=skipna) - cls.mad = mad + # pandas\core\generic.py:10470: error: "Type[NDFrame]" has no attribute + # "mad" [attr-defined] + cls.mad = mad # type: ignore[attr-defined] - cls.sem = _make_stat_function_ddof( + # pandas\core\generic.py:10472: error: "Type[NDFrame]" has no attribute + # "sem" [attr-defined] + cls.sem = _make_stat_function_ddof( # type: ignore[attr-defined] cls, "sem", name1=name1, @@ -10480,7 +10514,9 @@ def mad(self, axis=None, skipna=None, level=None): "using the ddof argument", func=nanops.nansem, ) - cls.var = _make_stat_function_ddof( + # pandas\core\generic.py:10483: error: "Type[NDFrame]" has no attribute + # "var" [attr-defined] + cls.var = _make_stat_function_ddof( # type: ignore[attr-defined] cls, "var", name1=name1, @@ -10490,7 +10526,9 @@ def mad(self, axis=None, skipna=None, level=None): "N-1 by default. This can be changed using the ddof argument", func=nanops.nanvar, ) - cls.std = _make_stat_function_ddof( + # pandas\core\generic.py:10493: error: "Type[NDFrame]" has no attribute + # "std" [attr-defined] + cls.std = _make_stat_function_ddof( # type: ignore[attr-defined] cls, "std", name1=name1, @@ -10502,7 +10540,9 @@ def mad(self, axis=None, skipna=None, level=None): func=nanops.nanstd, ) - cls.cummin = _make_cum_function( + # pandas\core\generic.py:10505: error: "Type[NDFrame]" has no attribute + # "cummin" [attr-defined] + cls.cummin = _make_cum_function( # type: ignore[attr-defined] cls, "cummin", name1=name1, @@ -10513,7 +10553,9 @@ def mad(self, axis=None, skipna=None, level=None): accum_func_name="min", examples=_cummin_examples, ) - cls.cumsum = _make_cum_function( + # pandas\core\generic.py:10516: error: "Type[NDFrame]" has no attribute + # "cumsum" [attr-defined] + cls.cumsum = _make_cum_function( # type: ignore[attr-defined] cls, "cumsum", name1=name1, @@ -10524,7 +10566,9 @@ def mad(self, axis=None, skipna=None, level=None): accum_func_name="sum", examples=_cumsum_examples, ) - cls.cumprod = _make_cum_function( + # pandas\core\generic.py:10527: error: "Type[NDFrame]" has no attribute + # "cumprod" [attr-defined] + cls.cumprod = _make_cum_function( # type: ignore[attr-defined] cls, "cumprod", name1=name1, @@ -10535,7 +10579,9 @@ def mad(self, axis=None, skipna=None, level=None): accum_func_name="prod", examples=_cumprod_examples, ) - cls.cummax = _make_cum_function( + # pandas\core\generic.py:10538: error: "Type[NDFrame]" has no attribute + # "cummax" [attr-defined] + cls.cummax = _make_cum_function( # type: ignore[attr-defined] cls, "cummax", name1=name1, @@ -10547,7 +10593,9 @@ def mad(self, axis=None, skipna=None, level=None): examples=_cummax_examples, ) - cls.sum = _make_min_count_stat_function( + # pandas\core\generic.py:10550: error: "Type[NDFrame]" has no attribute + # "sum" [attr-defined] + cls.sum = _make_min_count_stat_function( # type: ignore[attr-defined] cls, "sum", name1=name1, @@ -10559,7 +10607,9 @@ def mad(self, axis=None, skipna=None, level=None): see_also=_stat_func_see_also, examples=_sum_examples, ) - cls.mean = _make_stat_function( + # pandas\core\generic.py:10562: error: "Type[NDFrame]" has no attribute + # "mean" [attr-defined] + cls.mean = _make_stat_function( # type: ignore[attr-defined] cls, "mean", name1=name1, @@ -10568,7 +10618,9 @@ def mad(self, axis=None, skipna=None, level=None): desc="Return the mean of the values for the requested axis.", func=nanops.nanmean, ) - cls.skew = _make_stat_function( + # pandas\core\generic.py:10571: error: "Type[NDFrame]" has no attribute + # "skew" [attr-defined] + cls.skew = _make_stat_function( # type: ignore[attr-defined] cls, "skew", name1=name1, @@ -10577,7 +10629,9 @@ def mad(self, axis=None, skipna=None, level=None): desc="Return unbiased skew over requested axis.\n\nNormalized by N-1.", func=nanops.nanskew, ) - cls.kurt = _make_stat_function( + # pandas\core\generic.py:10580: error: "Type[NDFrame]" has no attribute + # "kurt" [attr-defined] + cls.kurt = _make_stat_function( # type: ignore[attr-defined] cls, "kurt", name1=name1, @@ -10589,8 +10643,15 @@ def mad(self, axis=None, skipna=None, level=None): "by N-1.", func=nanops.nankurt, ) - cls.kurtosis = cls.kurt - cls.prod = _make_min_count_stat_function( + # pandas\core\generic.py:10592: error: "Type[NDFrame]" has no attribute + # "kurtosis" [attr-defined] + + # pandas\core\generic.py:10592: error: "Type[NDFrame]" has no attribute + # "kurt" [attr-defined] + cls.kurtosis = cls.kurt # type: ignore[attr-defined] + # pandas\core\generic.py:10593: error: "Type[NDFrame]" has no attribute + # "prod" [attr-defined] + cls.prod = _make_min_count_stat_function( # type: ignore[attr-defined] cls, "prod", name1=name1, @@ -10600,8 +10661,15 @@ def mad(self, axis=None, skipna=None, level=None): func=nanops.nanprod, examples=_prod_examples, ) - cls.product = cls.prod - cls.median = _make_stat_function( + # pandas\core\generic.py:10603: error: "Type[NDFrame]" has no attribute + # "product" [attr-defined] + + # pandas\core\generic.py:10603: error: "Type[NDFrame]" has no attribute + # "prod" [attr-defined] + cls.product = cls.prod # type: ignore[attr-defined] + # pandas\core\generic.py:10604: error: "Type[NDFrame]" has no attribute + # "median" [attr-defined] + cls.median = _make_stat_function( # type: ignore[attr-defined] cls, "median", name1=name1, @@ -10610,7 +10678,9 @@ def mad(self, axis=None, skipna=None, level=None): desc="Return the median of the values for the requested axis.", func=nanops.nanmedian, ) - cls.max = _make_stat_function( + # pandas\core\generic.py:10613: error: "Type[NDFrame]" has no attribute + # "max" [attr-defined] + cls.max = _make_stat_function( # type: ignore[attr-defined] cls, "max", name1=name1, @@ -10623,7 +10693,9 @@ def mad(self, axis=None, skipna=None, level=None): see_also=_stat_func_see_also, examples=_max_examples, ) - cls.min = _make_stat_function( + # pandas\core\generic.py:10626: error: "Type[NDFrame]" has no attribute + # "min" [attr-defined] + cls.min = _make_stat_function( # type: ignore[attr-defined] cls, "min", name1=name1, @@ -11565,7 +11637,14 @@ def cum_func(self, axis=None, skipna=True, *args, **kwargs): axis = self._get_axis_number(axis) if axis == 1: - return cum_func(self.T, axis=0, skipna=skipna, *args, **kwargs).T + # pandas\core\generic.py:11568: error: "cum_func" gets multiple + # values for keyword argument "axis" [misc] + + # pandas\core\generic.py:11568: error: "cum_func" gets multiple + # values for keyword argument "skipna" [misc] + return cum_func( + self.T, axis=0, skipna=skipna, *args, **kwargs # type: ignore[misc] + ).T def block_accum_func(blk_values): values = blk_values.T if hasattr(blk_values, "T") else blk_values diff --git a/setup.cfg b/setup.cfg index 199cb95b75b03..7f5725600f280 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.generic] -check_untyped_defs=False - [mypy-pandas.core.groupby.base] check_untyped_defs=False From 2091145e186fc60a773fdd94873beff18aa6ca8a Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 20:21:30 +0100 Subject: [PATCH 17/45] [mypy-pandas.core.groupby.base] --- pandas/core/groupby/base.py | 24 ++++++++++++++++++++---- setup.cfg | 3 --- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pandas/core/groupby/base.py b/pandas/core/groupby/base.py index 2387427d15670..ccdd52ed7a55c 100644 --- a/pandas/core/groupby/base.py +++ b/pandas/core/groupby/base.py @@ -49,7 +49,9 @@ def _gotitem(self, key, ndim, subset=None): """ # create a new object to prevent aliasing if subset is None: - subset = self.obj + # pandas\core\groupby\base.py:52: error: "GotItemMixin" has no + # attribute "obj" [attr-defined] + subset = self.obj # type: ignore[attr-defined] # we need to make a shallow copy of ourselves # with the same groupby @@ -57,11 +59,25 @@ def _gotitem(self, key, ndim, subset=None): # Try to select from a DataFrame, falling back to a Series try: - groupby = self._groupby[key] + # pandas\core\groupby\base.py:60: error: "GotItemMixin" has no + # attribute "_groupby" [attr-defined] + groupby = self._groupby[key] # type: ignore[attr-defined] except IndexError: - groupby = self._groupby + # pandas\core\groupby\base.py:62: error: "GotItemMixin" has no + # attribute "_groupby" [attr-defined] + groupby = self._groupby # type: ignore[attr-defined] - self = type(self)(subset, groupby=groupby, parent=self, **kwargs) + # pandas\core\groupby\base.py:64: error: Too many arguments for + # "GotItemMixin" [call-arg] + + # pandas\core\groupby\base.py:64: error: Unexpected keyword argument + # "groupby" for "GotItemMixin" [call-arg] + + # pandas\core\groupby\base.py:64: error: Unexpected keyword argument + # "parent" for "GotItemMixin" [call-arg] + self = type(self)( + subset, groupby=groupby, parent=self, **kwargs # type: ignore[call-arg] + ) self._reset_cache() if subset.ndim == 2: if is_scalar(key) and key in subset or is_list_like(key): diff --git a/setup.cfg b/setup.cfg index 7f5725600f280..e7b05e20ecd11 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.groupby.base] -check_untyped_defs=False - [mypy-pandas.core.groupby.grouper] check_untyped_defs=False From 25b0a17434d41ebdad8de6d3d53d82d4ff7c1df2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 20:30:30 +0100 Subject: [PATCH 18/45] [mypy-pandas.core.groupby.grouper] --- pandas/core/groupby/grouper.py | 13 ++++++++++--- setup.cfg | 3 --- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index a509acb3604e1..e353ebacfb5cd 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -307,7 +307,10 @@ def _get_grouper(self, obj, validate: bool = True): a tuple of binner, grouper, obj (possibly sorted) """ self._set_grouper(obj) - self.grouper, _, self.obj = get_grouper( + # pandas\core\groupby\grouper.py:310: error: Value of type variable + # "FrameOrSeries" of "get_grouper" cannot be "Optional[Any]" + # [type-var] + self.grouper, _, self.obj = get_grouper( # type: ignore[type-var] self.obj, [self.key], axis=self.axis, @@ -345,7 +348,9 @@ def _set_grouper(self, obj: FrameOrSeries, sort: bool = False): if getattr(self.grouper, "name", None) == key and isinstance( obj, ABCSeries ): - ax = self._grouper.take(obj.index) + # pandas\core\groupby\grouper.py:348: error: Item "None" of + # "Optional[Any]" has no attribute "take" [union-attr] + ax = self._grouper.take(obj.index) # type: ignore else: if key not in obj._info_axis: raise KeyError(f"The grouper name {key} is not found") @@ -379,7 +384,9 @@ def _set_grouper(self, obj: FrameOrSeries, sort: bool = False): @property def groups(self): - return self.grouper.groups + # pandas\core\groupby\grouper.py:382: error: Item "None" of + # "Optional[Any]" has no attribute "groups" [union-attr] + return self.grouper.groups # type: ignore[union-attr] def __repr__(self) -> str: attrs_list = ( diff --git a/setup.cfg b/setup.cfg index e7b05e20ecd11..1e9f06e764987 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.groupby.grouper] -check_untyped_defs=False - [mypy-pandas.core.groupby.ops] check_untyped_defs=False From 2598d533b1fdc4c0024d5a8b586c2f08598d270f Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 4 Oct 2020 20:39:15 +0100 Subject: [PATCH 19/45] [mypy-pandas.core.groupby.ops] --- pandas/core/groupby/ops.py | 4 +++- setup.cfg | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 6051aa3022da1..d7ade70cfd4d5 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -886,7 +886,9 @@ def sort_idx(self): return get_group_index_sorter(self.labels, self.ngroups) def __iter__(self): - sdata = self._get_sorted_data() + # pandas\core\groupby\ops.py:889: error: Need type annotation for + # 'sdata' [var-annotated] + sdata = self._get_sorted_data() # type: ignore[var-annotated] if self.ngroups == 0: # we are inside a generator, rather than raise StopIteration diff --git a/setup.cfg b/setup.cfg index 1e9f06e764987..3cc75ef05b8cf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.groupby.ops] -check_untyped_defs=False - [mypy-pandas.core.indexes.base] check_untyped_defs=False From 464ef35f375a98bddbd6954d74d3b6a6b080a7ec Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 5 Oct 2020 10:25:29 +0100 Subject: [PATCH 20/45] [mypy-pandas.core.indexes.base] --- pandas/core/indexes/base.py | 195 ++++++++++++++++++++++++++++-------- setup.cfg | 3 - 2 files changed, 152 insertions(+), 46 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ff3d8bf05f9a5..dfc1a54fc47cc 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -966,7 +966,10 @@ def _format_attrs(self): """ Return a list of tuples of the (attr,formatted_value). """ - return format_object_attrs(self) + # pandas\core\indexes\base.py:969: error: Argument 1 to + # "format_object_attrs" has incompatible type "Index"; expected + # "Sequence[Any]" [arg-type] + return format_object_attrs(self) # type: ignore[arg-type] def _mpl_repr(self): # how to represent ourselves to matplotlib @@ -1603,8 +1606,12 @@ def droplevel(self, level=0): ) # The two checks above guarantee that here self is a MultiIndex - new_levels = list(self.levels) - new_codes = list(self.codes) + # pandas\core\indexes\base.py:1606: error: "Index" has no attribute + # "levels"; maybe "nlevels"? [attr-defined] + new_levels = list(self.levels) # type: ignore[attr-defined] + # pandas\core\indexes\base.py:1607: error: "Index" has no attribute + # "codes" [attr-defined] + new_codes = list(self.codes) # type: ignore[attr-defined] new_names = list(self.names) for i in levnums: @@ -3754,7 +3761,9 @@ def _get_leaf_sorter(labels): how = {"right": "left", "left": "right"}.get(how, how) level = left._get_level_number(level) - old_level = left.levels[level] + # pandas\core\indexes\base.py:3757: error: "Index" has no attribute + # "levels"; maybe "nlevels"? [attr-defined] + old_level = left.levels[level] # type: ignore[attr-defined] if not right.is_unique: raise NotImplementedError( @@ -3770,21 +3779,33 @@ def _get_leaf_sorter(labels): left_indexer = None join_index = left else: # sort the leaves - left_indexer = _get_leaf_sorter(left.codes[: level + 1]) + # pandas\core\indexes\base.py:3773: error: "Index" has no + # attribute "codes" [attr-defined] + left_indexer = _get_leaf_sorter( + left.codes[: level + 1] # type: ignore[attr-defined] + ) join_index = left[left_indexer] else: left_lev_indexer = ensure_int64(left_lev_indexer) rev_indexer = lib.get_reverse_indexer(left_lev_indexer, len(old_level)) + # pandas\core\indexes\base.py:3781: error: "Index" has no attribute + # "codes" [attr-defined] new_lev_codes = algos.take_nd( - rev_indexer, left.codes[level], allow_fill=False + rev_indexer, + left.codes[level], # type: ignore[attr-defined] + allow_fill=False, ) - new_codes = list(left.codes) + # pandas\core\indexes\base.py:3784: error: "Index" has no attribute + # "codes" [attr-defined] + new_codes = list(left.codes) # type: ignore[attr-defined] new_codes[level] = new_lev_codes - new_levels = list(left.levels) + # pandas\core\indexes\base.py:3787: error: "Index" has no attribute + # "levels"; maybe "nlevels"? [attr-defined] + new_levels = list(left.levels) # type: ignore[attr-defined] new_levels[level] = new_level if keep_order: # just drop missing values. o.w. keep order @@ -3827,11 +3848,17 @@ def _get_leaf_sorter(labels): ) if right_lev_indexer is not None: + # pandas\core\indexes\base.py:3831: error: "Index" has no attribute + # "codes" [attr-defined] right_indexer = algos.take_nd( - right_lev_indexer, join_index.codes[level], allow_fill=False + right_lev_indexer, + join_index.codes[level], # type: ignore[attr-defined] + allow_fill=False, ) else: - right_indexer = join_index.codes[level] + # pandas\core\indexes\base.py:3834: error: "Index" has no attribute + # "codes" [attr-defined] + right_indexer = join_index.codes[level] # type: ignore[attr-defined] if flip_order: left_indexer, right_indexer = right_indexer, left_indexer @@ -4798,7 +4825,11 @@ def get_indexer_for(self, target, **kwargs): """ if self._index_as_unique: return self.get_indexer(target, **kwargs) - indexer, _ = self.get_indexer_non_unique(target, **kwargs) + # pandas\core\indexes\base.py:4801: error: Too many arguments for + # "get_indexer_non_unique" of "Index" [call-arg] + indexer, _ = self.get_indexer_non_unique( + target, **kwargs # type: ignore[call-arg] + ) return indexer @property @@ -5394,36 +5425,90 @@ def _add_comparison_methods(cls): """ Add in comparison methods. """ - cls.__eq__ = _make_comparison_op(operator.eq, cls) - cls.__ne__ = _make_comparison_op(operator.ne, cls) - cls.__lt__ = _make_comparison_op(operator.lt, cls) - cls.__gt__ = _make_comparison_op(operator.gt, cls) - cls.__le__ = _make_comparison_op(operator.le, cls) - cls.__ge__ = _make_comparison_op(operator.ge, cls) + # pandas\core\indexes\base.py:5397: error: Cannot assign to a method + # [assignment] + cls.__eq__ = _make_comparison_op(operator.eq, cls) # type: ignore[assignment] + # pandas\core\indexes\base.py:5398: error: Cannot assign to a method + # [assignment] + cls.__ne__ = _make_comparison_op(operator.ne, cls) # type: ignore[assignment] + # pandas\core\indexes\base.py:5399: error: Unsupported left operand + # type for < ("Type[Index]") [operator] + cls.__lt__ = _make_comparison_op(operator.lt, cls) # type: ignore[operator] + # pandas\core\indexes\base.py:5400: error: Unsupported left operand + # type for > ("Type[Index]") [operator] + cls.__gt__ = _make_comparison_op(operator.gt, cls) # type: ignore[operator] + # pandas\core\indexes\base.py:5401: error: Unsupported left operand + # type for <= ("Type[Index]") [operator] + cls.__le__ = _make_comparison_op(operator.le, cls) # type: ignore[operator] + # pandas\core\indexes\base.py:5402: error: Unsupported left operand + # type for >= ("Type[Index]") [operator] + cls.__ge__ = _make_comparison_op(operator.ge, cls) # type: ignore[operator] @classmethod def _add_numeric_methods_binary(cls): """ Add in numeric methods. """ - cls.__add__ = _make_arithmetic_op(operator.add, cls) - cls.__radd__ = _make_arithmetic_op(ops.radd, cls) - cls.__sub__ = _make_arithmetic_op(operator.sub, cls) - cls.__rsub__ = _make_arithmetic_op(ops.rsub, cls) - cls.__rpow__ = _make_arithmetic_op(ops.rpow, cls) - cls.__pow__ = _make_arithmetic_op(operator.pow, cls) - - cls.__truediv__ = _make_arithmetic_op(operator.truediv, cls) - cls.__rtruediv__ = _make_arithmetic_op(ops.rtruediv, cls) - - cls.__mod__ = _make_arithmetic_op(operator.mod, cls) - cls.__rmod__ = _make_arithmetic_op(ops.rmod, cls) - cls.__floordiv__ = _make_arithmetic_op(operator.floordiv, cls) - cls.__rfloordiv__ = _make_arithmetic_op(ops.rfloordiv, cls) - cls.__divmod__ = _make_arithmetic_op(divmod, cls) - cls.__rdivmod__ = _make_arithmetic_op(ops.rdivmod, cls) - cls.__mul__ = _make_arithmetic_op(operator.mul, cls) - cls.__rmul__ = _make_arithmetic_op(ops.rmul, cls) + # pandas\core\indexes\base.py:5409: error: Unsupported left operand + # type for + ("Type[Index]") [operator] + cls.__add__ = _make_arithmetic_op(operator.add, cls) # type: ignore[operator] + # pandas\core\indexes\base.py:5410: error: "Type[Index]" has no + # attribute "__radd__" [attr-defined] + cls.__radd__ = _make_arithmetic_op(ops.radd, cls) # type: ignore[attr-defined] + # pandas\core\indexes\base.py:5411: error: Unsupported left operand + # type for - ("Type[Index]") [operator] + cls.__sub__ = _make_arithmetic_op(operator.sub, cls) # type: ignore[operator] + # pandas\core\indexes\base.py:5412: error: "Type[Index]" has no + # attribute "__rsub__" [attr-defined] + cls.__rsub__ = _make_arithmetic_op(ops.rsub, cls) # type: ignore[attr-defined] + # pandas\core\indexes\base.py:5413: error: "Type[Index]" has no + # attribute "__rpow__" [attr-defined] + cls.__rpow__ = _make_arithmetic_op(ops.rpow, cls) # type: ignore[attr-defined] + # pandas\core\indexes\base.py:5414: error: Unsupported left operand + # type for ** ("Type[Index]") [operator] + cls.__pow__ = _make_arithmetic_op(operator.pow, cls) # type: ignore[operator] + + # pandas\core\indexes\base.py:5416: error: Unsupported left operand + # type for / ("Type[Index]") [operator] + cls.__truediv__ = _make_arithmetic_op( # type: ignore[operator] + operator.truediv, cls + ) + # pandas\core\indexes\base.py:5417: error: "Type[Index]" has no + # attribute "__rtruediv__" [attr-defined] + cls.__rtruediv__ = _make_arithmetic_op( # type: ignore[attr-defined] + ops.rtruediv, cls + ) + + # pandas\core\indexes\base.py:5419: error: Unsupported left operand + # type for % ("Type[Index]") [operator] + cls.__mod__ = _make_arithmetic_op(operator.mod, cls) # type: ignore[operator] + # pandas\core\indexes\base.py:5420: error: "Type[Index]" has no + # attribute "__rmod__" [attr-defined] + cls.__rmod__ = _make_arithmetic_op(ops.rmod, cls) # type: ignore[attr-defined] + # pandas\core\indexes\base.py:5421: error: Unsupported left operand + # type for // ("Type[Index]") [operator] + cls.__floordiv__ = _make_arithmetic_op( # type: ignore[operator] + operator.floordiv, cls + ) + # pandas\core\indexes\base.py:5422: error: "Type[Index]" has no + # attribute "__rfloordiv__" [attr-defined] + cls.__rfloordiv__ = _make_arithmetic_op( # type: ignore[attr-defined] + ops.rfloordiv, cls + ) + # pandas\core\indexes\base.py:5423: error: Unsupported left operand + # type for divmod ("Type[Index]") [operator] + cls.__divmod__ = _make_arithmetic_op(divmod, cls) # type: ignore[operator] + # pandas\core\indexes\base.py:5424: error: "Type[Index]" has no + # attribute "__rdivmod__" [attr-defined] + cls.__rdivmod__ = _make_arithmetic_op( # type: ignore[attr-defined] + ops.rdivmod, cls + ) + # pandas\core\indexes\base.py:5425: error: Unsupported left operand + # type for * ("Type[Index]") [operator] + cls.__mul__ = _make_arithmetic_op(operator.mul, cls) # type: ignore[operator] + # pandas\core\indexes\base.py:5426: error: "Type[Index]" has no + # attribute "__rmul__" [attr-defined] + cls.__rmul__ = _make_arithmetic_op(ops.rmul, cls) # type: ignore[attr-defined] @classmethod def _add_numeric_methods_unary(cls): @@ -5440,10 +5525,26 @@ def _evaluate_numeric_unary(self): _evaluate_numeric_unary.__name__ = opstr return _evaluate_numeric_unary - cls.__neg__ = _make_evaluate_unary(operator.neg, "__neg__") - cls.__pos__ = _make_evaluate_unary(operator.pos, "__pos__") - cls.__abs__ = _make_evaluate_unary(np.abs, "__abs__") - cls.__inv__ = _make_evaluate_unary(lambda x: -x, "__inv__") + # pandas\core\indexes\base.py:5443: error: Unsupported operand type for + # unary - ("Type[Index]") [operator] + cls.__neg__ = _make_evaluate_unary( # type: ignore[operator] + operator.neg, "__neg__" + ) + # pandas\core\indexes\base.py:5444: error: Unsupported operand type for + # unary + ("Type[Index]") [operator] + cls.__pos__ = _make_evaluate_unary( # type: ignore[operator] + operator.pos, "__pos__" + ) + # pandas\core\indexes\base.py:5445: error: "Type[Index]" has no + # attribute "__abs__" [attr-defined] + cls.__abs__ = _make_evaluate_unary( # type: ignore[attr-defined] + np.abs, "__abs__" + ) + # pandas\core\indexes\base.py:5446: error: "Type[Index]" has no + # attribute "__inv__" [attr-defined] + cls.__inv__ = _make_evaluate_unary( # type: ignore[attr-defined] + lambda x: -x, "__inv__" + ) @classmethod def _add_numeric_methods(cls): @@ -5555,10 +5656,14 @@ def logical_func(self, *args, **kwargs): logical_func.__name__ = name return logical_func - cls.all = _make_logical_function( + # pandas\core\indexes\base.py:5558: error: "Type[Index]" has no + # attribute "all" [attr-defined] + cls.all = _make_logical_function( # type: ignore[attr-defined] "all", "Return whether all elements are True.", np.all ) - cls.any = _make_logical_function( + # pandas\core\indexes\base.py:5561: error: "Type[Index]" has no + # attribute "any" [attr-defined] + cls.any = _make_logical_function( # type: ignore[attr-defined] "any", "Return whether any element is True.", np.any ) @@ -5567,8 +5672,12 @@ def _add_logical_methods_disabled(cls): """ Add in logical methods to disable. """ - cls.all = make_invalid_op("all") - cls.any = make_invalid_op("any") + # pandas\core\indexes\base.py:5570: error: "Type[Index]" has no + # attribute "all" [attr-defined] + cls.all = make_invalid_op("all") # type: ignore[attr-defined] + # pandas\core\indexes\base.py:5571: error: "Type[Index]" has no + # attribute "any" [attr-defined] + cls.any = make_invalid_op("any") # type: ignore[attr-defined] @property def shape(self): diff --git a/setup.cfg b/setup.cfg index 3cc75ef05b8cf..f27f40cb58d6c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,9 +132,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.indexes.base] -check_untyped_defs=False - [mypy-pandas.core.indexes.category] check_untyped_defs=False From 98f4413c27a6baa2091ed2833471248ab762953a Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 6 Oct 2020 20:46:36 +0100 Subject: [PATCH 21/45] remove unused 'type: ignore' comments --- pandas/core/computation/pytables.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index 7190ed92b9719..d69e75e9b6c00 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -352,30 +352,21 @@ def evaluate(self): # too many values to create the expression? if len(values) <= self._max_selectors: vs = [self.generate(v) for v in values] - # pandas\core\computation\pytables.py:351: error: Incompatible - # types in assignment (expression has type "str", variable has - # type "None") [assignment] - self.condition = f"({' | '.join(vs)})" # type: ignore[assignment] + self.condition = f"({' | '.join(vs)})" # use a filter after reading else: return None else: - # pandas\core\computation\pytables.py:357: error: Incompatible - # types in assignment (expression has type "str", variable has type - # "None") [assignment] - self.condition = self.generate(values[0]) # type: ignore[assignment] + self.condition = self.generate(values[0]) return self class JointConditionBinOp(ConditionBinOp): def evaluate(self): - # pandas\core\computation\pytables.py:364: error: Incompatible types in - # assignment (expression has type "str", variable has type "None") - # [assignment] tmp = f"({self.lhs.condition} {self.op} {self.rhs.condition})" - self.condition = tmp # type: ignore[assignment] + self.condition = tmp return self From c85d090e0c2e8d4607b6bf8c9207daa9ea62ad0d Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 7 Oct 2020 12:36:08 +0100 Subject: [PATCH 22/45] ignore newly reported errors --- pandas/core/base.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index a86cd69399f67..2617db25236d1 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -192,12 +192,18 @@ def _selection_list(self): @cache_readonly def _selected_obj(self): - if self._selection is None or isinstance(self.obj, ABCSeries): + # pandas\core\base.py:195: error: "SelectionMixin" has no attribute + # "obj" [attr-defined] + if self._selection is None or isinstance( + self.obj, ABCSeries # type: ignore[attr-defined] + ): # pandas\core\base.py:194: error: "SelectionMixin" has no attribute # "obj" [attr-defined] return self.obj # type: ignore[attr-defined] else: - return self.obj[self._selection] + # pandas\core\base.py:204: error: "SelectionMixin" has no attribute + # "obj" [attr-defined] + return self.obj[self._selection] # type: ignore[attr-defined] @cache_readonly def ndim(self) -> int: @@ -205,8 +211,16 @@ def ndim(self) -> int: @cache_readonly def _obj_with_exclusions(self): - if self._selection is not None and isinstance(self.obj, ABCDataFrame): - return self.obj.reindex(columns=self._selection_list) + # pandas\core\base.py:209: error: "SelectionMixin" has no attribute + # "obj" [attr-defined] + if self._selection is not None and isinstance( + self.obj, ABCDataFrame # type: ignore[attr-defined] + ): + # pandas\core\base.py:217: error: "SelectionMixin" has no attribute + # "obj" [attr-defined] + return self.obj.reindex( # type: ignore[attr-defined] + columns=self._selection_list + ) # pandas\core\base.py:207: error: "SelectionMixin" has no attribute # "exclusions" [attr-defined] From 3c9f39b84b52f3b0d6448963b54dfe92b35b2408 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 7 Oct 2020 16:53:26 +0100 Subject: [PATCH 23/45] remove unused 'type: ignore' comment --- pandas/core/groupby/ops.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 9cd106c77eae9..1c18ef891b8c5 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -886,9 +886,7 @@ def sort_idx(self): return get_group_index_sorter(self.labels, self.ngroups) def __iter__(self): - # pandas\core\groupby\ops.py:889: error: Need type annotation for - # 'sdata' [var-annotated] - sdata = self._get_sorted_data() # type: ignore[var-annotated] + sdata = self._get_sorted_data() if self.ngroups == 0: # we are inside a generator, rather than raise StopIteration From 76b32280bced1b9ff9854b14e5171c1a9c12302d Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 7 Oct 2020 20:21:54 +0100 Subject: [PATCH 24/45] [mypy-pandas.core.indexes.category] --- pandas/core/indexes/category.py | 32 +++++++++++++++++++++++++++----- setup.cfg | 3 --- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index d3167189dbcc6..bfc8fdb143e98 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -312,7 +312,9 @@ def _format_attrs(self): "categories", ibase.default_pprint(self.categories, max_seq_items=max_categories), ), - ("ordered", self.ordered), + # pandas\core\indexes\category.py:315: error: "CategoricalIndex" + # has no attribute "ordered" [attr-defined] + ("ordered", self.ordered), # type: ignore[attr-defined] ] if self.name is not None: attrs.append(("name", ibase.default_pprint(self.name))) @@ -544,7 +546,12 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None): "method='nearest' not implemented yet for CategoricalIndex" ) - codes = self._values._validate_listlike(target._values) + # pandas\core\indexes\category.py:547: error: Item "ExtensionArray" of + # "Union[ExtensionArray, Any]" has no attribute "_validate_listlike" + # [union-attr] + codes = self._values._validate_listlike( # type: ignore[union-attr] + target._values + ) indexer, _ = self._engine.get_indexer_non_unique(codes) return ensure_platform_int(indexer) @@ -552,7 +559,12 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None): def get_indexer_non_unique(self, target): target = ibase.ensure_index(target) - codes = self._values._validate_listlike(target._values) + # pandas\core\indexes\category.py:555: error: Item "ExtensionArray" of + # "Union[ExtensionArray, Any]" has no attribute "_validate_listlike" + # [union-attr] + codes = self._values._validate_listlike( # type: ignore[union-attr] + target._values + ) indexer, missing = self._engine.get_indexer_non_unique(codes) return ensure_platform_int(indexer), missing @@ -658,7 +670,9 @@ def map(self, mapper): >>> idx.map({'a': 'first', 'b': 'second'}) Index(['first', 'second', nan], dtype='object') """ - mapped = self._values.map(mapper) + # pandas\core\indexes\category.py:661: error: Item "ExtensionArray" of + # "Union[ExtensionArray, Any]" has no attribute "map" [union-attr] + mapped = self._values.map(mapper) # type: ignore[union-attr] return Index(mapped, name=self.name) def delete(self, loc): @@ -701,7 +715,15 @@ def insert(self, loc: int, item): def _concat(self, to_concat, name): # if calling index is category, don't check dtype of others - codes = np.concatenate([self._is_dtype_compat(c).codes for c in to_concat]) + + # pandas\core\indexes\category.py:704: error: "bool" has no attribute + # "codes" [attr-defined] + codes = np.concatenate( + [ + self._is_dtype_compat(c).codes # type: ignore[attr-defined] + for c in to_concat + ] + ) cat = self._data._from_backing_data(codes) return type(self)._simple_new(cat, name=name) diff --git a/setup.cfg b/setup.cfg index 4392c3d463902..0104ad041212c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -133,9 +133,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.indexes.category] -check_untyped_defs=False - [mypy-pandas.core.indexes.datetimelike] check_untyped_defs=False From 0bc418a7872c92ca93c2b773c0a40dfb1cc53318 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 7 Oct 2020 20:45:42 +0100 Subject: [PATCH 25/45] [mypy-pandas.core.indexes.datetimelike] --- pandas/core/indexes/datetimelike.py | 22 ++++++++++++++++++---- setup.cfg | 3 --- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 5821ff0aca3c2..053aa52f97f35 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -755,7 +755,11 @@ def intersection(self, other, sort=False): start = right[0] if end < start: - result = type(self)(data=[], dtype=self.dtype, freq=self.freq) + # pandas\core\indexes\datetimelike.py:758: error: Unexpected + # keyword argument "freq" for "DatetimeTimedeltaMixin" [call-arg] + result = type(self)( + data=[], dtype=self.dtype, freq=self.freq # type: ignore[call-arg] + ) else: lslice = slice(*left.slice_locs(start, end)) left_chunk = left._values[lslice] @@ -884,7 +888,11 @@ def _union(self, other, sort): i8self = Int64Index._simple_new(self.asi8) i8other = Int64Index._simple_new(other.asi8) i8result = i8self._union(i8other, sort=sort) - result = type(self)(i8result, dtype=self.dtype, freq="infer") + # pandas\core\indexes\datetimelike.py:887: error: Unexpected + # keyword argument "freq" for "DatetimeTimedeltaMixin" [call-arg] + result = type(self)( + i8result, dtype=self.dtype, freq="infer" # type: ignore[call-arg] + ) return result # -------------------------------------------------------------------- @@ -933,8 +941,14 @@ def _maybe_utc_convert(self, other): raise TypeError("Cannot join tz-naive with tz-aware DatetimeIndex") if not timezones.tz_compare(self.tz, other.tz): - this = self.tz_convert("UTC") - other = other.tz_convert("UTC") + # pandas\core\indexes\datetimelike.py:936: error: + # "DatetimeTimedeltaMixin" has no attribute "tz_convert" + # [attr-defined] + this = self.tz_convert("UTC") # type: ignore[attr-defined] + # pandas\core\indexes\datetimelike.py:937: error: + # "DatetimeTimedeltaMixin" has no attribute "tz_convert" + # [attr-defined] + other = other.tz_convert("UTC") # type: ignore[attr-defined] return this, other # -------------------------------------------------------------------- diff --git a/setup.cfg b/setup.cfg index 0104ad041212c..97a00c06d88c1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -133,9 +133,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.indexes.datetimelike] -check_untyped_defs=False - [mypy-pandas.core.indexes.datetimes] check_untyped_defs=False From 68e63aa2da6596d978dacf78a29a90a87ed42748 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 8 Oct 2020 10:15:19 +0100 Subject: [PATCH 26/45] [mypy-pandas.core.indexes.datetimes] --- pandas/core/indexes/datetimes.py | 4 +++- setup.cfg | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 67b71ce63a6e3..bd39dcbcff97e 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -761,7 +761,9 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None): end_casted = self._maybe_cast_slice_bound(end, "right", kind) mask = (self <= end_casted) & mask - indexer = mask.nonzero()[0][::step] + # pandas\core\indexes\datetimes.py:764: error: "bool" has no + # attribute "nonzero" [attr-defined] + indexer = mask.nonzero()[0][::step] # type: ignore[attr-defined] if len(indexer) == len(self): return slice(None) else: diff --git a/setup.cfg b/setup.cfg index 97a00c06d88c1..c74128f2ca11c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -133,9 +133,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.indexes.datetimes] -check_untyped_defs=False - [mypy-pandas.core.indexes.extension] check_untyped_defs=False From ce89fde0d27243f07a78abe04f7c628239140938 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 8 Oct 2020 14:26:57 +0100 Subject: [PATCH 27/45] [mypy-pandas.core.indexes.extension] --- pandas/core/indexes/extension.py | 5 ++++- setup.cfg | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index c9367b7e2ee1d..c6a732a8022be 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -217,7 +217,10 @@ def __getitem__(self, key): if result.ndim == 1: return type(self)(result, name=self.name) # Unpack to ndarray for MPL compat - result = result._data + + # pandas\core\indexes\extension.py:220: error: "ExtensionArray" has + # no attribute "_data" [attr-defined] + result = result._data # type: ignore[attr-defined] # Includes cases where we get a 2D ndarray back for MPL compat deprecate_ndim_indexing(result) diff --git a/setup.cfg b/setup.cfg index e742f4dbc179c..44d8ebe712f5e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -133,9 +133,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.indexes.extension] -check_untyped_defs=False - [mypy-pandas.core.indexes.interval] check_untyped_defs=False From 8d84e756b5f9ea77ce14b9d9dd3feede91c12d32 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 8 Oct 2020 14:37:50 +0100 Subject: [PATCH 28/45] [mypy-pandas.core.indexes.interval] --- pandas/core/indexes/interval.py | 7 ++++++- setup.cfg | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 93117fbc22752..21d7490f785e2 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1305,7 +1305,12 @@ def interval_range( if isinstance(endpoint, Timestamp): range_func = date_range else: - range_func = timedelta_range + # pandas\core\indexes\interval.py:1308: error: Incompatible types + # in assignment (expression has type "Callable[[Any, Any, Any, Any, + # Any, Any], TimedeltaIndex]", variable has type "Callable[[Any, + # Any, Any, Any, Any, Any, Any, Any, KwArg(Any)], DatetimeIndex]") + # [assignment] + range_func = timedelta_range # type: ignore[assignment] breaks = range_func(start=start, end=end, periods=periods, freq=freq) diff --git a/setup.cfg b/setup.cfg index 44d8ebe712f5e..3e5f60a6f79fd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -133,9 +133,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.indexes.interval] -check_untyped_defs=False - [mypy-pandas.core.indexes.multi] check_untyped_defs=False From f7ff3b76b8bd34367985ec3c020c841ad04a9eab Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 8 Oct 2020 15:47:15 +0100 Subject: [PATCH 29/45] wip --- pandas/core/indexes/multi.py | 106 ++++++++++++++++++++------ pandas/core/internals/construction.py | 5 +- pandas/core/resample.py | 42 ++++++++-- pandas/core/reshape/concat.py | 20 ++++- pandas/core/reshape/merge.py | 5 +- pandas/core/series.py | 12 ++- setup.cfg | 18 ----- 7 files changed, 151 insertions(+), 57 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 0604f70316cfb..5acdb0aafc185 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1277,7 +1277,10 @@ def _format_attrs(self): """ Return a list of tuples of the (attr,formatted_value). """ - return format_object_attrs(self, include_dtype=False) + # pandas\core\indexes\multi.py:1280: error: Argument 1 to + # "format_object_attrs" has incompatible type "MultiIndex"; expected + # "Sequence[Any]" [arg-type] + return format_object_attrs(self, include_dtype=False) # type: ignore[arg-type] def _format_native_types(self, na_rep="nan", **kwargs): new_levels = [] @@ -1445,7 +1448,9 @@ def _set_names(self, names, level=None, validate=True): raise TypeError( f"{type(self).__name__}.name must be a hashable type" ) - self._names[lev] = name + # pandas\core\indexes\multi.py:1448: error: Cannot determine type + # of '__setitem__' [has-type] + self._names[lev] = name # type: ignore[has-type] # If .levels has been accessed, the names in our cache will be stale. self._reset_cache() @@ -3499,8 +3504,13 @@ def intersection(self, other, sort=False): if uniq_tuples is None: other_uniq = set(rvals) seen = set() + # pandas\core\indexes\multi.py:3503: error: "add" of "set" does not + # return a value [func-returns-value] uniq_tuples = [ - x for x in lvals if x in other_uniq and not (x in seen or seen.add(x)) + x + for x in lvals + if x in other_uniq + and not (x in seen or seen.add(x)) # type: ignore[func-returns-value] ] if sort is None: @@ -3691,34 +3701,80 @@ def _add_numeric_methods_add_sub_disabled(cls): """ Add in the numeric add/sub methods to disable. """ - cls.__add__ = make_invalid_op("__add__") - cls.__radd__ = make_invalid_op("__radd__") - cls.__iadd__ = make_invalid_op("__iadd__") - cls.__sub__ = make_invalid_op("__sub__") - cls.__rsub__ = make_invalid_op("__rsub__") - cls.__isub__ = make_invalid_op("__isub__") + # pandas\core\indexes\multi.py:3694: error: Unsupported left operand + # type for + ("Type[MultiIndex]") [operator] + cls.__add__ = make_invalid_op("__add__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3695: error: "Type[MultiIndex]" has no + # attribute "__radd__" [attr-defined] + cls.__radd__ = make_invalid_op("__radd__") # type: ignore[attr-defined] + # pandas\core\indexes\multi.py:3696: error: Cannot assign to a method + # [assignment] + cls.__iadd__ = make_invalid_op("__iadd__") # type: ignore[assignment] + # pandas\core\indexes\multi.py:3697: error: Unsupported left operand + # type for - ("Type[MultiIndex]") [operator] + cls.__sub__ = make_invalid_op("__sub__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3698: error: "Type[MultiIndex]" has no + # attribute "__rsub__" [attr-defined] + cls.__rsub__ = make_invalid_op("__rsub__") # type: ignore[attr-defined] + # pandas\core\indexes\multi.py:3699: error: "Type[MultiIndex]" has no + # attribute "__isub__" [attr-defined] + cls.__isub__ = make_invalid_op("__isub__") # type: ignore[attr-defined] @classmethod def _add_numeric_methods_disabled(cls): """ Add in numeric methods to disable other than add/sub. """ - cls.__pow__ = make_invalid_op("__pow__") - cls.__rpow__ = make_invalid_op("__rpow__") - cls.__mul__ = make_invalid_op("__mul__") - cls.__rmul__ = make_invalid_op("__rmul__") - cls.__floordiv__ = make_invalid_op("__floordiv__") - cls.__rfloordiv__ = make_invalid_op("__rfloordiv__") - cls.__truediv__ = make_invalid_op("__truediv__") - cls.__rtruediv__ = make_invalid_op("__rtruediv__") - cls.__mod__ = make_invalid_op("__mod__") - cls.__rmod__ = make_invalid_op("__rmod__") - cls.__divmod__ = make_invalid_op("__divmod__") - cls.__rdivmod__ = make_invalid_op("__rdivmod__") - cls.__neg__ = make_invalid_op("__neg__") - cls.__pos__ = make_invalid_op("__pos__") - cls.__abs__ = make_invalid_op("__abs__") - cls.__inv__ = make_invalid_op("__inv__") + # pandas\core\indexes\multi.py:3706: error: Unsupported left operand + # type for ** ("Type[MultiIndex]") [operator] + cls.__pow__ = make_invalid_op("__pow__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3707: error: "Type[MultiIndex]" has no + # attribute "__rpow__" [attr-defined] + cls.__rpow__ = make_invalid_op("__rpow__") # type: ignore[attr-defined] + # pandas\core\indexes\multi.py:3708: error: Unsupported left operand + # type for * ("Type[MultiIndex]") [operator] + cls.__mul__ = make_invalid_op("__mul__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3709: error: "Type[MultiIndex]" has no + # attribute "__rmul__" [attr-defined] + cls.__rmul__ = make_invalid_op("__rmul__") # type: ignore[attr-defined] + # pandas\core\indexes\multi.py:3710: error: Unsupported left operand + # type for // ("Type[MultiIndex]") [operator] + cls.__floordiv__ = make_invalid_op("__floordiv__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3711: error: "Type[MultiIndex]" has no + # attribute "__rfloordiv__" [attr-defined] + cls.__rfloordiv__ = make_invalid_op( # type: ignore[attr-defined] + "__rfloordiv__" + ) + # pandas\core\indexes\multi.py:3712: error: Unsupported left operand + # type for / ("Type[MultiIndex]") [operator] + cls.__truediv__ = make_invalid_op("__truediv__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3713: error: "Type[MultiIndex]" has no + # attribute "__rtruediv__" [attr-defined] + cls.__rtruediv__ = make_invalid_op("__rtruediv__") # type: ignore[attr-defined] + # pandas\core\indexes\multi.py:3714: error: Unsupported left operand + # type for % ("Type[MultiIndex]") [operator] + cls.__mod__ = make_invalid_op("__mod__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3715: error: "Type[MultiIndex]" has no + # attribute "__rmod__" [attr-defined] + cls.__rmod__ = make_invalid_op("__rmod__") # type: ignore[attr-defined] + # pandas\core\indexes\multi.py:3716: error: Unsupported left operand + # type for divmod ("Type[MultiIndex]") [operator] + cls.__divmod__ = make_invalid_op("__divmod__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3717: error: "Type[MultiIndex]" has no + # attribute "__rdivmod__" [attr-defined] + cls.__rdivmod__ = make_invalid_op("__rdivmod__") # type: ignore[attr-defined] + # pandas\core\indexes\multi.py:3718: error: Unsupported operand type + # for unary - ("Type[MultiIndex]") [operator] + cls.__neg__ = make_invalid_op("__neg__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3719: error: Unsupported operand type + # for unary + ("Type[MultiIndex]") [operator] + cls.__pos__ = make_invalid_op("__pos__") # type: ignore[operator] + # pandas\core\indexes\multi.py:3720: error: "Type[MultiIndex]" has no + # attribute "__abs__" [attr-defined] + cls.__abs__ = make_invalid_op("__abs__") # type: ignore[attr-defined] + # pandas\core\indexes\multi.py:3721: error: "Type[MultiIndex]" has no + # attribute "__inv__" [attr-defined] + cls.__inv__ = make_invalid_op("__inv__") # type: ignore[attr-defined] MultiIndex._add_numeric_methods_disabled() diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 6244f1bf0a2d2..bdafb2019c5bb 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -443,7 +443,10 @@ def get_names_from_index(data): if n is not None: index[i] = n else: - index[i] = f"Unnamed {count}" + # pandas\core\internals\construction.py:446: error: No overload + # variant of "__setitem__" of "list" matches argument types "int", + # "str" [call-overload] + index[i] = f"Unnamed {count}" # type: ignore[call-overload] count += 1 return index diff --git a/pandas/core/resample.py b/pandas/core/resample.py index f881f79cb5c1d..7d22d6980cbb3 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -93,7 +93,10 @@ def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs): self.as_index = True self.exclusions = set() self.binner = None - self.grouper = None + # pandas\core\resample.py:96: error: Incompatible types in assignment + # (expression has type "None", variable has type "BaseGrouper") + # [assignment] + self.grouper = None # type: ignore[assignment] if self.groupby is not None: self.groupby._set_grouper(self._convert_obj(obj), sort=True) @@ -405,14 +408,21 @@ def _apply_loffset(self, result): result : Series or DataFrame the result of resample """ + # pandas\core\resample.py:409: error: Cannot determine type of + # 'loffset' [has-type] needs_offset = ( - isinstance(self.loffset, (DateOffset, timedelta, np.timedelta64)) + isinstance( + self.loffset, # type: ignore[has-type] + (DateOffset, timedelta, np.timedelta64), + ) and isinstance(result.index, DatetimeIndex) and len(result.index) > 0 ) if needs_offset: - result.index = result.index + self.loffset + # pandas\core\resample.py:415: error: Cannot determine type of + # 'loffset' [has-type] + result.index = result.index + self.loffset # type: ignore[has-type] self.loffset = None return result @@ -847,7 +857,9 @@ def std(self, ddof=1, *args, **kwargs): Standard deviation of values within each group. """ nv.validate_resampler_func("std", args, kwargs) - return self._downsample("std", ddof=ddof) + # pandas\core\resample.py:850: error: Unexpected keyword argument + # "ddof" for "_downsample" [call-arg] + return self._downsample("std", ddof=ddof) # type: ignore[call-arg] def var(self, ddof=1, *args, **kwargs): """ @@ -864,7 +876,9 @@ def var(self, ddof=1, *args, **kwargs): Variance of values within each group. """ nv.validate_resampler_func("var", args, kwargs) - return self._downsample("var", ddof=ddof) + # pandas\core\resample.py:867: error: Unexpected keyword argument + # "ddof" for "_downsample" [call-arg] + return self._downsample("var", ddof=ddof) # type: ignore[call-arg] @doc(GroupBy.size) def size(self): @@ -917,7 +931,12 @@ def quantile(self, q=0.5, **kwargs): DataFrame.quantile DataFrameGroupBy.quantile """ - return self._downsample("quantile", q=q, **kwargs) + # pandas\core\resample.py:920: error: Unexpected keyword argument "q" + # for "_downsample" [call-arg] + + # pandas\core\resample.py:920: error: Too many arguments for + # "_downsample" [call-arg] + return self._downsample("quantile", q=q, **kwargs) # type: ignore[call-arg] # downsample methods @@ -969,7 +988,9 @@ def __init__(self, obj, *args, **kwargs): for attr in self._attributes: setattr(self, attr, kwargs.get(attr, getattr(parent, attr))) - super().__init__(None) + # pandas\core\resample.py:972: error: Too many arguments for "__init__" + # of "object" [call-arg] + super().__init__(None) # type: ignore[call-arg] self._groupby = groupby self._groupby.mutated = True self._groupby.grouper.mutated = True @@ -1034,7 +1055,12 @@ def _downsample(self, how, **kwargs): # do we have a regular frequency if ax.freq is not None or ax.inferred_freq is not None: - if len(self.grouper.binlabels) > len(ax) and how is None: + # pandas\core\resample.py:1037: error: "BaseGrouper" has no + # attribute "binlabels" [attr-defined] + if ( + len(self.grouper.binlabels) > len(ax) # type: ignore[attr-defined] + and how is None + ): # let's do an asfreq return self.asfreq() diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 91310a3659f33..29a7b11ccba85 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -467,7 +467,17 @@ def get_result(self): arrs = [ser._values for ser in self.objs] res = concat_compat(arrs, axis=0) - result = cons(res, index=self.new_axes[0], name=name, dtype=res.dtype) + # pandas\core\reshape\concat.py:470: error: Unexpected keyword + # argument "index" for "NDFrame" [call-arg] + + # pandas\core\reshape\concat.py:470: error: Unexpected keyword + # argument "name" for "NDFrame" [call-arg] + + # pandas\core\reshape\concat.py:470: error: Unexpected keyword + # argument "dtype" for "NDFrame" [call-arg] + result = cons( # type: ignore[call-arg] + res, index=self.new_axes[0], name=name, dtype=res.dtype + ) return result.__finalize__(self, method="concat") # combine as columns in a frame @@ -478,7 +488,13 @@ def get_result(self): cons = self.objs[0]._constructor_expanddim index, columns = self.new_axes - df = cons(data, index=index) + # pandas\core\reshape\concat.py:481: error: Argument 1 to + # "NDFrame" has incompatible type "Dict[int, FrameOrSeries]"; + # expected "BlockManager" [arg-type] + + # pandas\core\reshape\concat.py:484: error: Unexpected keyword + # argument "index" for "NDFrame" [call-arg] + df = cons(data, index=index) # type: ignore[arg-type, call-arg] df.columns = columns return df.__finalize__(self, method="concat") diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index 493ba87565220..803c0dc50c86c 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -963,7 +963,10 @@ def _get_merge_keys(self): """ left_keys = [] right_keys = [] - join_names = [] + # pandas\core\reshape\merge.py:966: error: Need type annotation for + # 'join_names' (hint: "join_names: List[] = ...") + # [var-annotated] + join_names = [] # type: ignore[var-annotated] right_drop = [] left_drop = [] diff --git a/pandas/core/series.py b/pandas/core/series.py index 0852f1b650ae6..4650a53a4c438 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1793,8 +1793,16 @@ def count(self, level=None): if isinstance(level, str): level = self.index._get_level_number(level) - lev = self.index.levels[level] - level_codes = np.array(self.index.codes[level], subok=False, copy=True) + # pandas\core\series.py:1796: error: "Index" has no attribute "levels"; + # maybe "nlevels"? [attr-defined] + lev = self.index.levels[level] # type: ignore[attr-defined] + # pandas\core\series.py:1797: error: "Index" has no attribute "codes" + # [attr-defined] + level_codes = np.array( + self.index.codes[level], # type: ignore[attr-defined] + subok=False, + copy=True, + ) mask = level_codes == -1 if mask.any(): diff --git a/setup.cfg b/setup.cfg index 3e5f60a6f79fd..befcc0ee0aeb9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -132,30 +132,12 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False - -[mypy-pandas.core.indexes.multi] -check_untyped_defs=False - [mypy-pandas.core.indexes.range] check_untyped_defs=False [mypy-pandas.core.internals.blocks] check_untyped_defs=False -[mypy-pandas.core.internals.construction] -check_untyped_defs=False - -[mypy-pandas.core.resample] -check_untyped_defs=False - -[mypy-pandas.core.reshape.concat] -check_untyped_defs=False - -[mypy-pandas.core.reshape.merge] -check_untyped_defs=False - -[mypy-pandas.core.series] -check_untyped_defs=False [mypy-pandas.core.window.common] check_untyped_defs=False From 2daf79f6816777ee5cbf79c4e220845f7311aeb5 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 8 Oct 2020 16:20:14 +0100 Subject: [PATCH 30/45] wip --- pandas/core/internals/blocks.py | 49 ++++++++++++++++++++++++--------- pandas/core/internals/ops.py | 12 ++++++-- pandas/core/window/common.py | 8 ++++-- pandas/core/window/expanding.py | 4 ++- pandas/core/window/rolling.py | 28 +++++++++++++++---- setup.cfg | 12 -------- 6 files changed, 77 insertions(+), 36 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 09f276be7d64a..7e46981d912b4 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2087,26 +2087,43 @@ def get_values(self, dtype=None): """ if is_object_dtype(dtype): # DTA/TDA constructor and astype can handle 2D - return self._holder(self.values).astype(object) - return self.values + + # pandas\core\internals\blocks.py:2090: error: + # "DatetimeLikeBlockMixin" has no attribute "values" + # [attr-defined] + return self._holder(self.values).astype( # type: ignore[attr-defined] + object + ) + # pandas\core\internals\blocks.py:2091: error: "DatetimeLikeBlockMixin" + # has no attribute "values" [attr-defined] + return self.values # type: ignore[attr-defined] def internal_values(self): # Override to return DatetimeArray and TimedeltaArray return self.array_values() def array_values(self): - return self._holder._simple_new(self.values) + # pandas\core\internals\blocks.py:2098: error: "DatetimeLikeBlockMixin" + # has no attribute "values" [attr-defined] + return self._holder._simple_new(self.values) # type: ignore[attr-defined] def iget(self, key): # GH#31649 we need to wrap scalars in Timestamp/Timedelta # TODO(EA2D): this can be removed if we ever have 2D EA - return self.array_values().reshape(self.shape)[key] + + # pandas\core\internals\blocks.py:2103: error: "DatetimeLikeBlockMixin" + # has no attribute "shape" [attr-defined] + return self.array_values().reshape(self.shape)[ # type: ignore[attr-defined] + key + ] def shift(self, periods, axis=0, fill_value=None): # TODO(EA2D) this is unnecessary if these blocks are backed by 2D EAs values = self.array_values() new_values = values.shift(periods, fill_value=fill_value, axis=axis) - return self.make_block_same_class(new_values) + # pandas\core\internals\blocks.py:2109: error: "DatetimeLikeBlockMixin" + # has no attribute "make_block_same_class" [attr-defined] + return self.make_block_same_class(new_values) # type: ignore[attr-defined] class DatetimeBlock(DatetimeLikeBlockMixin, Block): @@ -2510,7 +2527,10 @@ def replace(self, to_replace, value, inplace=False, regex=False, convert=True): both_lists = to_rep_is_list and value_is_list either_list = to_rep_is_list or value_is_list - result_blocks = [] + # pandas\core\internals\blocks.py:2513: error: Need type annotation for + # 'result_blocks' (hint: "result_blocks: List[] = ...") + # [var-annotated] + result_blocks = [] # type: ignore[var-annotated] blocks = [self] if not either_list and is_re(to_replace): @@ -2744,7 +2764,7 @@ def get_block_type(values, dtype=None): cls = CategoricalBlock elif issubclass(vtype, np.datetime64): assert not is_datetime64tz_dtype(values.dtype) - cls = DatetimeBlock + cls = DatetimeBlock # type: ignore[assignment] elif is_datetime64tz_dtype(values.dtype): cls = DatetimeTZBlock elif is_interval_dtype(dtype) or is_period_dtype(dtype): @@ -2752,18 +2772,21 @@ def get_block_type(values, dtype=None): elif is_extension_array_dtype(values.dtype): cls = ExtensionBlock elif issubclass(vtype, np.floating): - cls = FloatBlock + cls = FloatBlock # type: ignore[assignment] elif issubclass(vtype, np.timedelta64): assert issubclass(vtype, np.integer) - cls = TimeDeltaBlock + cls = TimeDeltaBlock # type: ignore[assignment] elif issubclass(vtype, np.complexfloating): - cls = ComplexBlock + cls = ComplexBlock # type: ignore[assignment] elif issubclass(vtype, np.integer): - cls = IntBlock + cls = IntBlock # type: ignore[assignment] elif dtype == np.bool_: - cls = BoolBlock + cls = BoolBlock # type: ignore[assignment] else: - cls = ObjectBlock + # pandas\core\internals\blocks.py:2766: error: Incompatible types in + # assignment (expression has type "Type[ObjectBlock]", variable has + # type "Type[ExtensionBlock]") [assignment] + cls = ObjectBlock # type: ignore[assignment] return cls diff --git a/pandas/core/internals/ops.py b/pandas/core/internals/ops.py index d7ea5d613d96a..89124d24a76c7 100644 --- a/pandas/core/internals/ops.py +++ b/pandas/core/internals/ops.py @@ -23,7 +23,9 @@ def _iter_block_pairs( for n, blk in enumerate(left.blocks): locs = blk.mgr_locs - blk_vals = blk.values + # pandas\core\internals\ops.py:26: error: Cannot determine type of + # 'values' [has-type] + blk_vals = blk.values # type: ignore[has-type] left_ea = not isinstance(blk_vals, np.ndarray) @@ -95,8 +97,12 @@ def _get_same_shape_values( """ Slice lblk.values to align with rblk. Squeeze if we have EAs. """ - lvals = lblk.values - rvals = rblk.values + # pandas\core\internals\ops.py:98: error: Cannot determine type of 'values' + # [has-type] + lvals = lblk.values # type: ignore[has-type] + # pandas\core\internals\ops.py:99: error: Cannot determine type of 'values' + # [has-type] + rvals = rblk.values # type: ignore[has-type] # Require that the indexing into lvals be slice-like assert rblk.mgr_locs.is_slice_like, rblk.mgr_locs diff --git a/pandas/core/window/common.py b/pandas/core/window/common.py index 2e7e7cd47c336..b2d4c5a4c9575 100644 --- a/pandas/core/window/common.py +++ b/pandas/core/window/common.py @@ -56,7 +56,9 @@ def __init__(self, obj, *args, **kwargs): self._groupby = groupby self._groupby.mutated = True self._groupby.grouper.mutated = True - super().__init__(obj, *args, **kwargs) + # pandas\core\window\common.py:59: error: Too many arguments for + # "__init__" of "object" [call-arg] + super().__init__(obj, *args, **kwargs) # type: ignore[call-arg] corr = _dispatch("corr", other=None, pairwise=None) cov = _dispatch("cov", other=None, pairwise=None) @@ -81,7 +83,9 @@ def _apply( # TODO: can we de-duplicate with _dispatch? def f(x, name=name, *args): - x = self._shallow_copy(x) + # pandas\core\window\common.py:84: error: "WindowGroupByMixin" has + # no attribute "_shallow_copy" [attr-defined] + x = self._shallow_copy(x) # type: ignore[attr-defined] if isinstance(name, str): return getattr(x, name)(*args, **kwargs) diff --git a/pandas/core/window/expanding.py b/pandas/core/window/expanding.py index 319944fd48eae..c5091c14664e9 100644 --- a/pandas/core/window/expanding.py +++ b/pandas/core/window/expanding.py @@ -128,7 +128,9 @@ def aggregate(self, func, *args, **kwargs): @Substitution(name="expanding") @Appender(_shared_docs["count"]) def count(self, **kwargs): - return super().count(**kwargs) + # pandas\core\window\expanding.py:131: error: Too many arguments for + # "count" [call-arg] + return super().count(**kwargs) # type: ignore[call-arg] @Substitution(name="expanding") @Appender(_shared_docs["apply"]) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index af3bba4edf343..b8c5a5c9daa2d 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1218,7 +1218,10 @@ def mean(self, *args, **kwargs): def var(self, ddof=1, *args, **kwargs): nv.validate_window_func("var", args, kwargs) window_func = partial(self._get_roll_func("roll_weighted_var"), ddof=ddof) - window_func = get_weighted_roll_func(window_func) + # pandas\core\window\rolling.py:1221: error: Incompatible types in + # assignment (expression has type "Callable[..., Any]", variable has + # type "partial[Any]") [assignment] + window_func = get_weighted_roll_func(window_func) # type: ignore[assignment] kwargs.pop("name", None) return self._apply( window_func, center=self.center, is_weighted=True, name="var", **kwargs @@ -1392,7 +1395,9 @@ def apply( def _generate_cython_apply_func(self, args, kwargs, raw, offset, func): from pandas import Series - window_func = partial( + # pandas\core\window\rolling.py:1395: error: "partial" gets multiple + # values for keyword argument "func" [misc] + window_func = partial( # type: ignore[misc] self._get_cython_func_type("roll_generic"), args=args, kwargs=kwargs, @@ -1730,9 +1735,15 @@ def cov(self, other=None, pairwise=None, ddof=1, **kwargs): else: # GH 16058: offset window if self.is_freq_type: - window = self.win_freq + # pandas\core\window\rolling.py:1733: error: Incompatible types + # in assignment (expression has type "None", variable has type + # "BaseIndexer") [assignment] + window = self.win_freq # type: ignore[assignment] else: - window = self._get_window(other) + # pandas\core\window\rolling.py:1735: error: Incompatible types + # in assignment (expression has type "int", variable has type + # "BaseIndexer") [assignment] + window = self._get_window(other) # type: ignore[assignment] def _get_cov(X, Y): # GH #12373 : rolling functions error on float32 data @@ -1877,7 +1888,14 @@ def corr(self, other=None, pairwise=None, **kwargs): if isinstance(self.window, BaseIndexer): window = self.window else: - window = self._get_window(other) if not self.is_freq_type else self.win_freq + # pandas\core\window\rolling.py:1880: error: Incompatible types in + # assignment (expression has type "Optional[int]", variable has + # type "BaseIndexer") [assignment] + window = ( + self._get_window(other) # type: ignore[assignment] + if not self.is_freq_type + else self.win_freq + ) def _get_corr(a, b): a = a.rolling( diff --git a/setup.cfg b/setup.cfg index 843caec70c343..a3a948de8b925 100644 --- a/setup.cfg +++ b/setup.cfg @@ -133,18 +133,6 @@ check_untyped_defs=False [mypy-pandas._version] check_untyped_defs=False -[mypy-pandas.core.internals.blocks] -check_untyped_defs=False - -[mypy-pandas.core.window.common] -check_untyped_defs=False - -[mypy-pandas.core.window.expanding] -check_untyped_defs=False - -[mypy-pandas.core.window.rolling] -check_untyped_defs=False - [mypy-pandas.io.clipboard] check_untyped_defs=False From 5d919192720f7e21a65acb236e8ce6bf9cb85822 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 9 Oct 2020 11:46:57 +0100 Subject: [PATCH 31/45] io --- pandas/io/excel/_base.py | 12 ++- pandas/io/formats/console.py | 8 +- pandas/io/formats/excel.py | 25 ++++- pandas/io/formats/format.py | 18 +++- pandas/io/formats/style.py | 10 +- pandas/io/json/_json.py | 65 ++++++++++--- pandas/io/parsers.py | 173 ++++++++++++++++++++++++++++------- pandas/io/pytables.py | 67 +++++++++++--- pandas/io/sas/sas7bdat.py | 112 +++++++++++++++++++---- pandas/io/sas/sas_xport.py | 88 +++++++++++++++--- pandas/io/stata.py | 23 ++++- setup.cfg | 32 ------- 12 files changed, 491 insertions(+), 142 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 604b7e12ec243..6369704e5d447 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -741,7 +741,10 @@ def __init__( self.mode = mode def __fspath__(self): - return stringify_path(self.path) + # pandas\io\excel\_base.py:744: error: Argument 1 to "stringify_path" + # has incompatible type "Optional[Any]"; expected "Union[str, Path, + # IO[Any], IOBase]" [arg-type] + return stringify_path(self.path) # type: ignore[arg-type] def _get_sheet_name(self, sheet_name): if sheet_name is None: @@ -792,7 +795,12 @@ def check_extension(cls, ext): """ if ext.startswith("."): ext = ext[1:] - if not any(ext in extension for extension in cls.supported_extensions): + # pandas\io\excel\_base.py:795: error: "Callable[[ExcelWriter], Any]" + # has no attribute "__iter__" (not iterable) [attr-defined] + if not any( + ext in extension + for extension in cls.supported_extensions # type: ignore[attr-defined] + ): raise ValueError(f"Invalid extension for engine '{cls.engine}': '{ext}'") else: return True diff --git a/pandas/io/formats/console.py b/pandas/io/formats/console.py index 50e69f7e8b435..ab9c9fe995008 100644 --- a/pandas/io/formats/console.py +++ b/pandas/io/formats/console.py @@ -69,7 +69,9 @@ def check_main(): return not hasattr(main, "__file__") or get_option("mode.sim_interactive") try: - return __IPYTHON__ or check_main() + # pandas\io\formats\console.py:72: error: Name '__IPYTHON__' is not + # defined [name-defined] + return __IPYTHON__ or check_main() # type: ignore[name-defined] except NameError: return check_main() @@ -83,7 +85,9 @@ def in_ipython_frontend(): bool """ try: - ip = get_ipython() + # pandas\io\formats\console.py:86: error: Name 'get_ipython' is not + # defined [name-defined] + ip = get_ipython() # type: ignore[name-defined] return "zmq" in str(type(ip)).lower() except NameError: pass diff --git a/pandas/io/formats/excel.py b/pandas/io/formats/excel.py index 4cd19800d4e26..b7d4e5e1d753b 100644 --- a/pandas/io/formats/excel.py +++ b/pandas/io/formats/excel.py @@ -590,10 +590,17 @@ def _format_header_regular(self): colnames = self.columns if has_aliases: - if len(self.header) != len(self.columns): + # pandas\io\formats\excel.py:593: error: Argument 1 to "len" + # has incompatible type "Union[Sequence[Optional[Hashable]], + # bool]"; expected "Sized" [arg-type] + if len(self.header) != len(self.columns): # type: ignore[arg-type] + # pandas\io\formats\excel.py:595: error: Argument 1 to + # "len" has incompatible type + # "Union[Sequence[Optional[Hashable]], bool]"; expected + # "Sized" [arg-type] + tmp = len(self.header) # type: ignore[arg-type] raise ValueError( - f"Writing {len(self.columns)} cols but got {len(self.header)} " - "aliases" + f"Writing {len(self.columns)} cols but got {tmp} aliases" ) else: colnames = self.header @@ -615,7 +622,10 @@ def _format_header(self): "" ] * len(self.columns) if reduce(lambda x, y: x and y, map(lambda x: x != "", row)): - gen2 = ( + # pandas\io\formats\excel.py:618: error: Incompatible types in + # assignment (expression has type "Generator[ExcelCell, None, + # None]", variable has type "Tuple[]") [assignment] + gen2 = ( # type: ignore[assignment] ExcelCell(self.rowcounter, colindex, val, self.header_style) for colindex, val in enumerate(row) ) @@ -805,7 +815,12 @@ def write( if isinstance(writer, ExcelWriter): need_save = False else: - writer = ExcelWriter(stringify_path(writer), engine=engine) + # pandas\io\formats\excel.py:808: error: Cannot instantiate + # abstract class 'ExcelWriter' with abstract attributes 'engine', + # 'save', 'supported_extensions' and 'write_cells' [abstract] + writer = ExcelWriter( # type: ignore[abstract] + stringify_path(writer), engine=engine + ) need_save = True formatted_cells = self.get_formatted_cells() diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 13010bb2ef147..e9099c0ee2018 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1407,7 +1407,19 @@ def _value_formatter( if float_format: def base_formatter(v): - return float_format(value=v) if notna(v) else self.na_rep + # pandas\io\formats\format.py:1410: error: "str" not callable + # [operator] + + # pandas\io\formats\format.py:1410: error: Unexpected keyword + # argument "value" for "__call__" of "EngFormatter" [call-arg] + + # pandas\io\formats\format.py:1410: error: "None" not callable + # [misc] + return ( + float_format(value=v) # type: ignore[operator,call-arg,misc] + if notna(v) + else self.na_rep + ) else: @@ -1847,7 +1859,9 @@ def _make_fixed_width( def just(x): if conf_max is not None: - if (conf_max > 3) & (adj.len(x) > max_len): + # pandas\io\formats\format.py:1850: error: Item "None" of + # "Optional[TextAdjustment]" has no attribute "len" [union-attr] + if (conf_max > 3) & (adj.len(x) > max_len): # type: ignore[union-attr] x = x[: max_len - 3] + "..." return x diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 1df37da3da8d0..24ed1ca7b59e6 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -1511,7 +1511,15 @@ def from_custom_template(cls, searchpath, name): """ loader = jinja2.ChoiceLoader([jinja2.FileSystemLoader(searchpath), cls.loader]) - class MyStyler(cls): + # pandas\io\formats\style.py:1514: error: Variable "cls" is not valid + # as a type [valid-type] + + # pandas\io\formats\style.py:1514: note: See + # https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases + + # pandas\io\formats\style.py:1514: error: Invalid base class "cls" + # [misc] + class MyStyler(cls): # type: ignore[valid-type,misc] env = jinja2.Environment(loader=loader) template = env.get_template(name) diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index ef684469dffbb..d64e2ca99880f 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -777,7 +777,10 @@ def read(self): obj = self._get_object_parser(lines_json) else: data = ensure_str(self.data) - data = data.split("\n") + # pandas\io\json\_json.py:780: error: Incompatible types in + # assignment (expression has type "List[str]", variable has + # type "str") [assignment] + data = data.split("\n") # type: ignore[assignment] obj = self._get_object_parser(self._combine_lines(data)) else: obj = self._get_object_parser(self.data) @@ -872,7 +875,9 @@ def __init__( self.json = json if orient is None: - orient = self._default_orient + # pandas\io\json\_json.py:875: error: "Parser" has no attribute + # "_default_orient" [attr-defined] + orient = self._default_orient # type: ignore[attr-defined] self.orient = orient self.dtype = dtype @@ -900,9 +905,16 @@ def check_keys_split(self, decoded): """ Checks that dict has only the appropriate keys for orient='split'. """ - bad_keys = set(decoded.keys()).difference(set(self._split_keys)) + # pandas\io\json\_json.py:903: error: "Parser" has no attribute + # "_split_keys" [attr-defined] + bad_keys = set(decoded.keys()).difference( + set(self._split_keys) # type: ignore[attr-defined] + ) if bad_keys: - bad_keys = ", ".join(bad_keys) + # pandas\io\json\_json.py:905: error: Incompatible types in + # assignment (expression has type "str", variable has type + # "Set[Any]") [assignment] + bad_keys = ", ".join(bad_keys) # type: ignore[assignment] raise ValueError(f"JSON data had unexpected key(s): {bad_keys}") def parse(self): @@ -910,10 +922,14 @@ def parse(self): # try numpy numpy = self.numpy if numpy: - self._parse_numpy() + # pandas\io\json\_json.py:913: error: "Parser" has no attribute + # "_parse_numpy" [attr-defined] + self._parse_numpy() # type: ignore[attr-defined] else: - self._parse_no_numpy() + # pandas\io\json\_json.py:916: error: "Parser" has no attribute + # "_parse_no_numpy" [attr-defined] + self._parse_no_numpy() # type: ignore[attr-defined] if self.obj is None: return None @@ -926,10 +942,14 @@ def _convert_axes(self): """ Try to convert axes. """ - for axis_name in self.obj._AXIS_ORDERS: + # pandas\io\json\_json.py:929: error: Item "None" of "Optional[Any]" + # has no attribute "_AXIS_ORDERS" [union-attr] + for axis_name in self.obj._AXIS_ORDERS: # type: ignore[union-attr] new_axis, result = self._try_convert_data( name=axis_name, - data=self.obj._get_axis(axis_name), + # pandas\io\json\_json.py:932: error: Item "None" of + # "Optional[Any]" has no attribute "_get_axis" [union-attr] + data=self.obj._get_axis(axis_name), # type: ignore[union-attr] use_dtypes=False, convert_dates=True, ) @@ -1083,7 +1103,12 @@ def _parse_numpy(self): self.check_keys_split(decoded) self.obj = create_series_with_explicit_dtype(**decoded) elif self.orient in ["columns", "index"]: - self.obj = create_series_with_explicit_dtype(*data, dtype_if_empty=object) + # pandas\io\json\_json.py:1086: error: + # "create_series_with_explicit_dtype" gets multiple values for + # keyword argument "dtype_if_empty" [misc] + self.obj = create_series_with_explicit_dtype( + *data, dtype_if_empty=object # type: ignore[misc] + ) else: self.obj = create_series_with_explicit_dtype(data, dtype_if_empty=object) @@ -1177,7 +1202,9 @@ def _process_converter(self, f, filt=None): needs_new_obj = False new_obj = dict() - for i, (col, c) in enumerate(self.obj.items()): + # pandas\io\json\_json.py:1180: error: Item "None" of "Optional[Any]" + # has no attribute "items" [union-attr] + for i, (col, c) in enumerate(self.obj.items()): # type: ignore[union-attr] if filt(col, c): new_data, result = f(col, c) if result: @@ -1188,8 +1215,22 @@ def _process_converter(self, f, filt=None): if needs_new_obj: # possibly handle dup columns - new_obj = DataFrame(new_obj, index=self.obj.index) - new_obj.columns = self.obj.columns + + # pandas\io\json\_json.py:1191: error: Incompatible types in + # assignment (expression has type "DataFrame", variable has type + # "Dict[int, Any]") [assignment] + + # pandas\io\json\_json.py:1191: error: Item "None" of + # "Optional[Any]" has no attribute "index" [union-attr] + new_obj = DataFrame( # type: ignore[assignment] + new_obj, index=self.obj.index # type: ignore[union-attr] + ) + # pandas\io\json\_json.py:1192: error: "Dict[int, Any]" has no + # attribute "columns" [attr-defined] + + # pandas\io\json\_json.py:1192: error: Item "None" of + # "Optional[Any]" has no attribute "columns" [union-attr] + new_obj.columns = self.obj.columns # type: ignore[attr-defined,union-attr] self.obj = new_obj def _try_convert_types(self): diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index ede4fdc5e1d8b..c5e7d26cacab2 100644 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -904,7 +904,10 @@ def _get_options_with_defaults(self, engine): options[argname] = value if engine == "python-fwf": - for argname, default in _fwf_defaults.items(): + # pandas\io\parsers.py:907: error: Incompatible types in assignment + # (expression has type "object", variable has type "Union[int, str, + # None]") [assignment] + for argname, default in _fwf_defaults.items(): # type: ignore[assignment] options[argname] = kwds.get(argname, default) return options @@ -1096,9 +1099,18 @@ def __next__(self): def _make_engine(self, engine="c"): mapping = { - "c": CParserWrapper, - "python": PythonParser, - "python-fwf": FixedWidthFieldParser, + # pandas\io\parsers.py:1099: error: Dict entry 0 has incompatible + # type "str": "Type[CParserWrapper]"; expected "str": + # "Type[ParserBase]" [dict-item] + "c": CParserWrapper, # type: ignore[dict-item] + # pandas\io\parsers.py:1100: error: Dict entry 1 has incompatible + # type "str": "Type[PythonParser]"; expected "str": + # "Type[ParserBase]" [dict-item] + "python": PythonParser, # type: ignore[dict-item] + # pandas\io\parsers.py:1101: error: Dict entry 2 has incompatible + # type "str": "Type[FixedWidthFieldParser]"; expected "str": + # "Type[ParserBase]" [dict-item] + "python-fwf": FixedWidthFieldParser, # type: ignore[dict-item] } try: klass = mapping[engine] @@ -1556,7 +1568,9 @@ def _maybe_dedup_names(self, names): # would be nice! if self.mangle_dupe_cols: names = list(names) # so we can index - counts = defaultdict(int) + # pandas\io\parsers.py:1559: error: Need type annotation for + # 'counts' [var-annotated] + counts = defaultdict(int) # type: ignore[var-annotated] is_potential_mi = _is_potential_multi_index(names, self.index_col) for i, col in enumerate(names): @@ -1601,7 +1615,9 @@ def _make_index(self, data, alldata, columns, indexnamerow=False): # add names for the index if indexnamerow: coffset = len(indexnamerow) - len(columns) - index = index.set_names(indexnamerow[:coffset]) + # pandas\io\parsers.py:1604: error: Item "None" of "Optional[Any]" + # has no attribute "set_names" [union-attr] + index = index.set_names(indexnamerow[:coffset]) # type: ignore[union-attr] # maybe create a mi on the columns columns = self._maybe_make_multi_index_columns(columns, self.col_names) @@ -1675,7 +1691,9 @@ def _agg_index(self, index, try_parse_dates=True): col_na_fvalues = set() if isinstance(self.na_values, dict): - col_name = self.index_names[i] + # pandas\io\parsers.py:1678: error: Value of type + # "Optional[Any]" is not indexable [index] + col_name = self.index_names[i] # type: ignore[index] if col_name is not None: col_na_values, col_na_fvalues = _get_na_values( col_name, self.na_values, self.na_fvalues, self.keep_default_na @@ -1994,7 +2012,12 @@ def __init__(self, src, **kwds): self.index_names = index_names if self._reader.header is None and not passed_names: - self.index_names = [None] * len(self.index_names) + # pandas\io\parsers.py:1997: error: Argument 1 to "len" has + # incompatible type "Optional[Any]"; expected "Sized" + # [arg-type] + self.index_names = [None] * len( + self.index_names # type: ignore[arg-type] + ) self._implicit_index = self._reader.leading_cols > 0 @@ -2027,14 +2050,20 @@ def _set_noconvert_columns(self): usecols = self.names[:] else: # Usecols is empty. - usecols = None + + # pandas\io\parsers.py:2030: error: Incompatible types in + # assignment (expression has type "None", variable has type + # "List[Any]") [assignment] + usecols = None # type: ignore[assignment] def _set(x): if usecols is not None and is_integer(x): x = usecols[x] if not is_integer(x): - x = names.index(x) + # pandas\io\parsers.py:2037: error: Item "None" of + # "Optional[Any]" has no attribute "index" [union-attr] + x = names.index(x) # type: ignore[union-attr] self._reader.set_noconvert(x) @@ -2128,7 +2157,11 @@ def read(self, nrows=None): data = sorted(data.items()) # ugh, mutation - names = list(self.orig_names) + + # pandas\io\parsers.py:2131: error: Argument 1 to "list" has + # incompatible type "Optional[Any]"; expected "Iterable[Any]" + # [arg-type] + names = list(self.orig_names) # type: ignore[arg-type] names = self._maybe_dedup_names(names) if self.usecols is not None: @@ -2477,7 +2510,10 @@ def read(self, rows=None): # done with first read, next time raise StopIteration self._first_chunk = False - columns = list(self.orig_names) + # pandas\io\parsers.py:2480: error: Argument 1 to "list" has + # incompatible type "Optional[Any]"; expected "Iterable[Any]" + # [arg-type] + columns = list(self.orig_names) # type: ignore[arg-type] if not len(content): # pragma: no cover # DataFrame with the right metadata, even though it's length 0 names = self._maybe_dedup_names(self.orig_names) @@ -2525,7 +2561,9 @@ def _exclude_implicit_index(self, alldata): # legacy def get_chunk(self, size=None): if size is None: - size = self.chunksize + # pandas\io\parsers.py:2528: error: "PythonParser" has no attribute + # "chunksize" [attr-defined] + size = self.chunksize # type: ignore[attr-defined] return self.read(rows=size) def _convert_data(self, data): @@ -2534,8 +2572,15 @@ def _clean_mapping(mapping): """converts col numbers to names""" clean = {} for col, v in mapping.items(): - if isinstance(col, int) and col not in self.orig_names: - col = self.orig_names[col] + # pandas\io\parsers.py:2537: error: Unsupported right operand + # type for in ("Optional[Any]") [operator] + if ( + isinstance(col, int) + and col not in self.orig_names # type: ignore[operator] + ): + # pandas\io\parsers.py:2538: error: Value of type + # "Optional[Any]" is not indexable [index] + col = self.orig_names[col] # type: ignore[index] clean[col] = v return clean @@ -2555,8 +2600,15 @@ def _clean_mapping(mapping): na_value = self.na_values[col] na_fvalue = self.na_fvalues[col] - if isinstance(col, int) and col not in self.orig_names: - col = self.orig_names[col] + # pandas\io\parsers.py:2558: error: Unsupported right operand + # type for in ("Optional[Any]") [operator] + if ( + isinstance(col, int) + and col not in self.orig_names # type: ignore[operator] + ): + # pandas\io\parsers.py:2559: error: Value of type + # "Optional[Any]" is not indexable [index] + col = self.orig_names[col] # type: ignore[index] clean_na_values[col] = na_value clean_na_fvalues[col] = na_fvalue @@ -2577,7 +2629,10 @@ def _infer_columns(self): names = self.names num_original_columns = 0 clear_buffer = True - unnamed_cols = set() + # pandas\io\parsers.py:2580: error: Need type annotation for + # 'unnamed_cols' (hint: "unnamed_cols: Set[] = ...") + # [var-annotated] + unnamed_cols = set() # type: ignore[var-annotated] if self.header is not None: header = self.header @@ -2591,7 +2646,9 @@ def _infer_columns(self): have_mi_columns = False header = [header] - columns = [] + # pandas\io\parsers.py:2594: error: Need type annotation for + # 'columns' (hint: "columns: List[] = ...") [var-annotated] + columns = [] # type: ignore[var-annotated] for level, hr in enumerate(header): try: line = self._buffered_line() @@ -2636,7 +2693,9 @@ def _infer_columns(self): this_columns.append(c) if not have_mi_columns and self.mangle_dupe_cols: - counts = defaultdict(int) + # pandas\io\parsers.py:2639: error: Need type annotation + # for 'counts' [var-annotated] + counts = defaultdict(int) # type: ignore[var-annotated] for i, col in enumerate(this_columns): cur_count = counts[col] @@ -2660,10 +2719,16 @@ def _infer_columns(self): if lc != unnamed_count and lc - ic > unnamed_count: clear_buffer = False - this_columns = [None] * lc + # pandas\io\parsers.py:2663: error: List item 0 has + # incompatible type "None"; expected "str" + # [list-item] + this_columns = [None] * lc # type: ignore[list-item] self.buf = [self.buf[-1]] - columns.append(this_columns) + # pandas\io\parsers.py:2666: error: Argument 1 to "append" of + # "list" has incompatible type "List[str]"; expected + # "List[None]" [arg-type] + columns.append(this_columns) # type: ignore[arg-type] unnamed_cols.update({this_columns[i] for i in this_unnamed_cols}) if len(columns) == 1: @@ -2708,9 +2773,19 @@ def _infer_columns(self): if not names: if self.prefix: - columns = [[f"{self.prefix}{i}" for i in range(ncols)]] + # pandas\io\parsers.py:2711: error: List comprehension has + # incompatible type List[str]; expected List[None] [misc] + columns = [ + [ + f"{self.prefix}{i}" # type: ignore[misc] + for i in range(ncols) + ] + ] else: - columns = [list(range(ncols))] + # pandas\io\parsers.py:2713: error: Argument 1 to "list" + # has incompatible type "range"; expected "Iterable[None]" + # [arg-type] + columns = [list(range(ncols))] # type: ignore[arg-type] columns = self._handle_usecols(columns, columns[0]) else: if self.usecols is None or len(names) >= num_original_columns: @@ -2862,7 +2937,10 @@ def _next_line(self): else: while self.skipfunc(self.pos): self.pos += 1 - next(self.data) + # pandas\io\parsers.py:2865: error: Argument 1 to "next" has + # incompatible type "Optional[Any]"; expected "Iterator[Any]" + # [arg-type] + next(self.data) # type: ignore[arg-type] while True: orig_line = self._next_iter_line(row_num=self.pos + 1) @@ -2923,7 +3001,10 @@ def _next_iter_line(self, row_num): row_num : The row number of the line being parsed. """ try: - return next(self.data) + # pandas\io\parsers.py:2926: error: Argument 1 to "next" has + # incompatible type "Optional[Any]"; expected "Iterator[Any]" + # [arg-type] + return next(self.data) # type: ignore[arg-type] except csv.Error as e: if self.warn_bad_lines or self.error_bad_lines: msg = str(e) @@ -3156,12 +3237,19 @@ def _rows_to_cols(self, content): for i, a in enumerate(zipped_content) if ( i < len(self.index_col) - or i - len(self.index_col) in self._col_indices + # pandas\io\parsers.py:3159: error: Unsupported right + # operand type for in ("Optional[Any]") [operator] + or i - len(self.index_col) # type: ignore[operator] + in self._col_indices ) ] else: zipped_content = [ - a for i, a in enumerate(zipped_content) if i in self._col_indices + # pandas\io\parsers.py:3164: error: Unsupported right + # operand type for in ("Optional[Any]") [operator] + a + for i, a in enumerate(zipped_content) + if i in self._col_indices # type: ignore[operator] ] return zipped_content @@ -3206,7 +3294,10 @@ def _get_lines(self, rows=None): try: if rows is not None: for _ in range(rows): - new_rows.append(next(self.data)) + # pandas\io\parsers.py:3209: error: Argument 1 to + # "next" has incompatible type "Optional[Any]"; + # expected "Iterator[Any]" [arg-type] + new_rows.append(next(self.data)) # type: ignore[arg-type] lines.extend(new_rows) else: rows = 0 @@ -3384,7 +3475,9 @@ def _clean_na_values(na_values, keep_default_na=True): na_values = STR_NA_VALUES else: na_values = set() - na_fvalues = set() + # pandas\io\parsers.py:3387: error: Need type annotation for + # 'na_fvalues' (hint: "na_fvalues: Set[] = ...") [var-annotated] + na_fvalues = set() # type: ignore[var-annotated] elif isinstance(na_values, dict): old_na_values = na_values.copy() na_values = {} # Prevent aliasing. @@ -3401,7 +3494,12 @@ def _clean_na_values(na_values, keep_default_na=True): v = set(v) | STR_NA_VALUES na_values[k] = v - na_fvalues = {k: _floatify_na_values(v) for k, v in na_values.items()} + # pandas\io\parsers.py:3404: error: Incompatible types in assignment + # (expression has type "Dict[Any, Any]", variable has type "Set[Any]") + # [assignment] + na_fvalues = { # type: ignore[assignment] + k: _floatify_na_values(v) for k, v in na_values.items() + } else: if not is_list_like(na_values): na_values = [na_values] @@ -3442,7 +3540,10 @@ def _clean_index_names(columns, index_col, unnamed_cols): # Only clean index names that were placeholders. for i, name in enumerate(index_names): if isinstance(name, str) and name in unnamed_cols: - index_names[i] = None + # pandas\io\parsers.py:3445: error: No overload variant of + # "__setitem__" of "list" matches argument types "int", "None" + # [call-overload] + index_names[i] = None # type: ignore[call-overload] return index_names, columns, index_col @@ -3519,11 +3620,15 @@ def _stringify_na_values(na_values): result.append(f"{v}.0") result.append(str(v)) - result.append(v) + # pandas\io\parsers.py:3522: error: Argument 1 to "append" of + # "list" has incompatible type "float"; expected "str" [arg-type] + result.append(v) # type: ignore[arg-type] except (TypeError, ValueError, OverflowError): pass try: - result.append(int(x)) + # pandas\io\parsers.py:3526: error: Argument 1 to "append" of + # "list" has incompatible type "int"; expected "str" [arg-type] + result.append(int(x)) # type: ignore[arg-type] except (TypeError, ValueError, OverflowError): pass return set(result) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 3e3330fa4378f..139d92ae488f6 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -565,7 +565,9 @@ def __fspath__(self): def root(self): """ return the root node """ self._check_if_open() - return self._handle.root + # pandas\io\pytables.py:568: error: Item "None" of "Optional[Any]" has + # no attribute "root" [union-attr] + return self._handle.root # type: ignore[union-attr] @property def filename(self): @@ -1395,13 +1397,24 @@ def groups(self): self._check_if_open() return [ g - for g in self._handle.walk_groups() + # pandas\io\pytables.py:1398: error: Item "None" of "Optional[Any]" + # has no attribute "walk_groups" [union-attr] + for g in self._handle.walk_groups() # type: ignore[union-attr] if ( - not isinstance(g, _table_mod.link.Link) + # pandas\io\pytables.py:1400: error: Item "None" of + # "Optional[Any]" has no attribute "link" [union-attr] + not isinstance(g, _table_mod.link.Link) # type: ignore[union-attr] and ( getattr(g._v_attrs, "pandas_type", None) or getattr(g, "table", None) - or (isinstance(g, _table_mod.table.Table) and g._v_name != "table") + # pandas\io\pytables.py:1404: error: Item "None" of + # "Optional[Any]" has no attribute "table" [union-attr] + or ( + isinstance( + g, _table_mod.table.Table # type: ignore[union-attr] + ) + and g._v_name != "table" + ) ) ) ] @@ -1437,7 +1450,9 @@ def walk(self, where="/"): """ _tables() self._check_if_open() - for g in self._handle.walk_groups(where): + # pandas\io\pytables.py:1440: error: Item "None" of "Optional[Any]" has + # no attribute "walk_groups" [union-attr] + for g in self._handle.walk_groups(where): # type: ignore[union-attr] if getattr(g._v_attrs, "pandas_type", None) is not None: continue @@ -1446,7 +1461,11 @@ def walk(self, where="/"): for child in g._v_children.values(): pandas_type = getattr(child._v_attrs, "pandas_type", None) if pandas_type is None: - if isinstance(child, _table_mod.group.Group): + # pandas\io\pytables.py:1449: error: Item "None" of + # "Optional[Any]" has no attribute "group" [union-attr] + if isinstance( + child, _table_mod.group.Group # type: ignore[union-attr] + ): groups.append(child._v_name) else: leaves.append(child._v_name) @@ -1864,7 +1883,11 @@ def __iter__(self): current = self.start while current < self.stop: stop = min(current + self.chunksize, self.stop) - value = self.func(None, None, self.coordinates[current:stop]) + # pandas\io\pytables.py:1867: error: Value of type "None" is not + # indexable [index] + value = self.func( + None, None, self.coordinates[current:stop] # type: ignore[index] + ) current = stop if value is None or not len(value): continue @@ -3433,7 +3456,12 @@ def get_attrs(self): self.nan_rep = getattr(self.attrs, "nan_rep", None) self.encoding = _ensure_encoding(getattr(self.attrs, "encoding", None)) self.errors = _ensure_decoded(getattr(self.attrs, "errors", "strict")) - self.levels = getattr(self.attrs, "levels", None) or [] + # pandas\io\pytables.py:3436: error: Incompatible types in assignment + # (expression has type "Union[Any, List[Any]]", variable has type + # "int") [assignment] + self.levels = ( + getattr(self.attrs, "levels", None) or [] # type: ignore[assignment] + ) self.index_axes = [a for a in self.indexables if a.is_an_indexable] self.values_axes = [a for a in self.indexables if not a.is_an_indexable] @@ -4563,7 +4591,9 @@ def write(self, obj, **kwargs): """ we are going to write this as a frame table """ name = obj.name or "values" obj, self.levels = self.validate_multiindex(obj) - cols = list(self.levels) + # pandas\io\pytables.py:4566: error: No overload variant of "list" + # matches argument type "int" [call-overload] + cols = list(self.levels) # type: ignore[call-overload] cols.append(name) obj.columns = cols return super().write(obj=obj, **kwargs) @@ -4589,7 +4619,10 @@ def get_attrs(self): """ retrieve our attributes """ self.non_index_axes = [] self.nan_rep = None - self.levels = [] + # pandas\io\pytables.py:4592: error: Incompatible types in assignment + # (expression has type "List[]", variable has type "int") + # [assignment] + self.levels = [] # type: ignore[assignment] self.index_axes = [a for a in self.indexables if a.is_an_indexable] self.values_axes = [a for a in self.indexables if not a.is_an_indexable] @@ -4626,7 +4659,10 @@ def indexables(self): meta=meta, metadata=md, ) - _indexables.append(dc) + # pandas\io\pytables.py:4629: error: Argument 1 to "append" of + # "list" has incompatible type "GenericDataIndexableCol"; expected + # "GenericIndexCol" [arg-type] + _indexables.append(dc) # type: ignore[arg-type] return _indexables @@ -4652,7 +4688,10 @@ def write(self, obj, data_columns=None, **kwargs): elif data_columns is True: data_columns = obj.columns.tolist() obj, self.levels = self.validate_multiindex(obj) - for n in self.levels: + # pandas\io\pytables.py:4655: error: "int" has no attribute "__iter__"; + # maybe "__str__", "__int__", or "__invert__"? (not iterable) + # [attr-defined] + for n in self.levels: # type: ignore[attr-defined] if n not in data_columns: data_columns.insert(0, n) return super().write(obj=obj, data_columns=data_columns, **kwargs) @@ -5170,7 +5209,9 @@ def select_coords(self): start += nrows if self.stop is None: stop = nrows - elif stop < 0: + # pandas\io\pytables.py:5173: error: Unsupported operand types for > + # ("int" and "None") [operator] + elif stop < 0: # type: ignore[operator] stop += nrows if self.condition is not None: diff --git a/pandas/io/sas/sas7bdat.py b/pandas/io/sas/sas7bdat.py index f2ee642d8fd42..3f14f03e3474f 100644 --- a/pandas/io/sas/sas7bdat.py +++ b/pandas/io/sas/sas7bdat.py @@ -173,8 +173,16 @@ def close(self): def _get_properties(self): # Check magic number - self._path_or_buf.seek(0) - self._cached_page = self._path_or_buf.read(288) + + # pandas\io\sas\sas7bdat.py:176: error: Item "str" of "Union[str, + # IO[Any], IOBase]" has no attribute "seek" [union-attr] + self._path_or_buf.seek(0) # type: ignore[union-attr] + # pandas\io\sas\sas7bdat.py:177: error: Item "str" of "Union[str, + # IO[Any], IOBase]" has no attribute "read" [union-attr] + + # pandas\io\sas\sas7bdat.py:177: error: Item "IOBase" of "Union[str, + # IO[Any], IOBase]" has no attribute "read" [union-attr] + self._cached_page = self._path_or_buf.read(288) # type: ignore[union-attr] if self._cached_page[0 : len(const.magic)] != const.magic: self.close() raise ValueError("magic number mismatch (not a SAS file?)") @@ -249,7 +257,15 @@ def _get_properties(self): ) # Read the rest of the header into cached_page. - buf = self._path_or_buf.read(self.header_length - 288) + + # pandas\io\sas\sas7bdat.py:252: error: Item "str" of "Union[str, + # IO[Any], IOBase]" has no attribute "read" [union-attr] + + # pandas\io\sas\sas7bdat.py:252: error: Item "IOBase" of "Union[str, + # IO[Any], IOBase]" has no attribute "read" [union-attr] + buf = self._path_or_buf.read( # type: ignore[union-attr] + self.header_length - 288 + ) self._cached_page += buf if len(self._cached_page) != self.header_length: self.close() @@ -330,8 +346,16 @@ def _read_int(self, offset, width): def _read_bytes(self, offset, length): if self._cached_page is None: - self._path_or_buf.seek(offset) - buf = self._path_or_buf.read(length) + # pandas\io\sas\sas7bdat.py:333: error: Item "str" of "Union[str, + # IO[Any], IOBase]" has no attribute "seek" [union-attr] + self._path_or_buf.seek(offset) # type: ignore[union-attr] + # pandas\io\sas\sas7bdat.py:334: error: Item "str" of "Union[str, + # IO[Any], IOBase]" has no attribute "read" [union-attr] + + # pandas\io\sas\sas7bdat.py:334: error: Item "IOBase" of + # "Union[str, IO[Any], IOBase]" has no attribute "read" + # [union-attr] + buf = self._path_or_buf.read(length) # type: ignore[union-attr] if len(buf) < length: self.close() msg = f"Unable to read {length:d} bytes from file position {offset:d}." @@ -346,7 +370,15 @@ def _read_bytes(self, offset, length): def _parse_metadata(self): done = False while not done: - self._cached_page = self._path_or_buf.read(self._page_length) + # pandas\io\sas\sas7bdat.py:349: error: Item "str" of "Union[str, + # IO[Any], IOBase]" has no attribute "read" [union-attr] + + # pandas\io\sas\sas7bdat.py:349: error: Item "IOBase" of + # "Union[str, IO[Any], IOBase]" has no attribute "read" + # [union-attr] + self._cached_page = self._path_or_buf.read( # type: ignore[union-attr] + self._page_length + ) if len(self._cached_page) <= 0: break if len(self._cached_page) != self._page_length: @@ -424,10 +456,18 @@ def _process_subheader_pointers(self, offset, subheader_pointer_index): subheader_type = self._read_int(total_offset, 1) x = _subheader_pointer() - x.offset = subheader_offset - x.length = subheader_length - x.compression = subheader_compression - x.ptype = subheader_type + # pandas\io\sas\sas7bdat.py:427: error: "_subheader_pointer" has no + # attribute "offset" [attr-defined] + x.offset = subheader_offset # type: ignore[attr-defined] + # pandas\io\sas\sas7bdat.py:428: error: "_subheader_pointer" has no + # attribute "length" [attr-defined] + x.length = subheader_length # type: ignore[attr-defined] + # pandas\io\sas\sas7bdat.py:429: error: "_subheader_pointer" has no + # attribute "compression" [attr-defined] + x.compression = subheader_compression # type: ignore[attr-defined] + # pandas\io\sas\sas7bdat.py:430: error: "_subheader_pointer" has no + # attribute "ptype" [attr-defined] + x.ptype = subheader_type # type: ignore[attr-defined] return x @@ -522,7 +562,10 @@ def _process_columntext_subheader(self, offset, length): compression_literal = "" for cl in const.compression_literals: if cl in cname_raw: - compression_literal = cl + # pandas\io\sas\sas7bdat.py:525: error: Incompatible types + # in assignment (expression has type "bytes", variable has + # type "str") [assignment] + compression_literal = cl # type: ignore[assignment] self.compression = compression_literal offset -= self._int_length @@ -539,7 +582,13 @@ def _process_columntext_subheader(self, offset, length): offset1 += 4 buf = self._read_bytes(offset1, self._lcp) self.creator_proc = buf[0 : self._lcp] - elif compression_literal == const.rle_compression: + # pandas\io\sas\sas7bdat.py:542: error: Non-overlapping equality + # check (left operand type: "str", right operand type: "bytes") + # [comparison-overlap] + elif ( + compression_literal # type: ignore[comparison-overlap] + == const.rle_compression + ): offset1 = offset + 40 if self.U64: offset1 += 4 @@ -658,12 +707,30 @@ def _process_format_subheader(self, offset, length): current_column_number = len(self.columns) col = _column() - col.col_id = current_column_number - col.name = self.column_names[current_column_number] - col.label = column_label - col.format = column_format - col.ctype = self._column_types[current_column_number] - col.length = self._column_data_lengths[current_column_number] + # pandas\io\sas\sas7bdat.py:661: error: "_column" has no attribute + # "col_id" [attr-defined] + col.col_id = current_column_number # type: ignore[attr-defined] + # pandas\io\sas\sas7bdat.py:662: error: "_column" has no attribute + # "name" [attr-defined] + col.name = self.column_names[ # type: ignore[attr-defined] + current_column_number + ] + # pandas\io\sas\sas7bdat.py:663: error: "_column" has no attribute + # "label" [attr-defined] + col.label = column_label # type: ignore[attr-defined] + # pandas\io\sas\sas7bdat.py:664: error: "_column" has no attribute + # "format" [attr-defined] + col.format = column_format # type: ignore[attr-defined] + # pandas\io\sas\sas7bdat.py:665: error: "_column" has no attribute + # "ctype" [attr-defined] + col.ctype = self._column_types[ # type: ignore[attr-defined] + current_column_number + ] + # pandas\io\sas\sas7bdat.py:666: error: "_column" has no attribute + # "length" [attr-defined] + col.length = self._column_data_lengths[ # type: ignore[attr-defined] + current_column_number + ] self.column_formats.append(column_format) self.columns.append(col) @@ -704,7 +771,14 @@ def read(self, nrows=None): def _read_next_page(self): self._current_page_data_subheader_pointers = [] - self._cached_page = self._path_or_buf.read(self._page_length) + # pandas\io\sas\sas7bdat.py:707: error: Item "str" of "Union[str, + # IO[Any], IOBase]" has no attribute "read" [union-attr] + + # pandas\io\sas\sas7bdat.py:707: error: Item "IOBase" of "Union[str, + # IO[Any], IOBase]" has no attribute "read" [union-attr] + self._cached_page = self._path_or_buf.read( # type: ignore[union-attr] + self._page_length + ) if len(self._cached_page) <= 0: return True elif len(self._cached_page) != self._page_length: diff --git a/pandas/io/sas/sas_xport.py b/pandas/io/sas/sas_xport.py index 9727ec930119b..d7553722a5e3a 100644 --- a/pandas/io/sas/sas_xport.py +++ b/pandas/io/sas/sas_xport.py @@ -347,22 +347,48 @@ def _read_header(self): field = field.ljust(140) fieldstruct = struct.unpack(">hhhh8s40s8shhh2s8shhl52s", field) - field = dict(zip(_fieldkeys, fieldstruct)) - del field["_"] - field["ntype"] = types[field["ntype"]] - fl = field["field_length"] - if field["ntype"] == "numeric" and ((fl < 2) or (fl > 8)): + # pandas\io\sas\sas_xport.py:350: error: Incompatible types in + # assignment (expression has type "Dict[str, Any]", variable has + # type "bytes") [assignment] + field = dict(zip(_fieldkeys, fieldstruct)) # type: ignore[assignment] + # pandas\io\sas\sas_xport.py:351: error: "bytes" has no attribute + # "__delitem__"; maybe "__getitem__"? [attr-defined] + del field["_"] # type: ignore[attr-defined] + # pandas\io\sas\sas_xport.py:352: error: Unsupported target for + # indexed assignment ("bytes") [index] + + # pandas\io\sas\sas_xport.py:352: error: No overload variant of + # "__getitem__" of "bytes" matches argument type "str" + # [call-overload] + field["ntype"] = types[field["ntype"]] # type: ignore[index,call-overload] + # pandas\io\sas\sas_xport.py:353: error: No overload variant of + # "__getitem__" of "bytes" matches argument type "str" + # [call-overload] + fl = field["field_length"] # type: ignore[call-overload] + # pandas\io\sas\sas_xport.py:354: error: No overload variant of + # "__getitem__" of "bytes" matches argument type "str" + # [call-overload] + if field["ntype"] == "numeric" and ( # type: ignore[call-overload] + (fl < 2) or (fl > 8) + ): self.close() msg = f"Floating field width {fl} is not between 2 and 8." raise TypeError(msg) - for k, v in field.items(): + # pandas\io\sas\sas_xport.py:359: error: "bytes" has no attribute + # "items" [attr-defined] + for k, v in field.items(): # type: ignore[attr-defined] try: - field[k] = v.strip() + # pandas\io\sas\sas_xport.py:361: error: Unsupported target + # for indexed assignment ("bytes") [index] + field[k] = v.strip() # type: ignore[index] except AttributeError: pass - obs_length += field["field_length"] + # pandas\io\sas\sas_xport.py:365: error: No overload variant of + # "__getitem__" of "bytes" matches argument type "str" + # [call-overload] + obs_length += field["field_length"] # type: ignore[call-overload] fields += [field] header = self._get_row() @@ -375,11 +401,21 @@ def _read_header(self): self.record_start = self.filepath_or_buffer.tell() self.nobs = self._record_count() - self.columns = [x["name"].decode() for x in self.fields] + # pandas\io\sas\sas_xport.py:378: error: No overload variant of + # "__getitem__" of "bytes" matches argument type "str" [call-overload] + self.columns = [ + x["name"].decode() for x in self.fields # type: ignore[call-overload] + ] # Setup the dtype. dtypel = [ - ("s" + str(i), "S" + str(field["field_length"])) + # pandas\io\sas\sas_xport.py:382: error: No overload variant of + # "__getitem__" of "bytes" matches argument type "str" + # [call-overload] + ( + "s" + str(i), + "S" + str(field["field_length"]), # type: ignore[call-overload] + ) for i, field in enumerate(self.fields) ] dtype = np.dtype(dtypel) @@ -412,7 +448,13 @@ def _record_count(self) -> int: last_card = np.frombuffer(last_card, dtype=np.uint64) # 8 byte blank - ix = np.flatnonzero(last_card == 2314885530818453536) + + # pandas\io\sas\sas_xport.py:415: error: Non-overlapping equality check + # (left operand type: "bytes", right operand type: + # "Literal[2314885530818453536]") [comparison-overlap] + ix = np.flatnonzero( + last_card == 2314885530818453536 # type: ignore[comparison-overlap] + ) if len(ix) == 0: tail_pad = 0 @@ -468,13 +510,24 @@ def read(self, nrows=None): df = pd.DataFrame(index=range(read_lines)) for j, x in enumerate(self.columns): vec = data["s" + str(j)] - ntype = self.fields[j]["ntype"] + # pandas\io\sas\sas_xport.py:471: error: No overload variant of + # "__getitem__" of "bytes" matches argument type "str" + # [call-overload] + ntype = self.fields[j]["ntype"] # type: ignore[call-overload] if ntype == "numeric": - vec = _handle_truncated_float_vec(vec, self.fields[j]["field_length"]) + # pandas\io\sas\sas_xport.py:473: error: No overload variant of + # "__getitem__" of "bytes" matches argument type "str" + # [call-overload] + vec = _handle_truncated_float_vec( + vec, self.fields[j]["field_length"] # type: ignore[call-overload] + ) miss = self._missing_double(vec) v = _parse_float_vec(vec) v[miss] = np.nan - elif self.fields[j]["ntype"] == "char": + # pandas\io\sas\sas_xport.py:477: error: No overload variant of + # "__getitem__" of "bytes" matches argument type "str" + # [call-overload] + elif self.fields[j]["ntype"] == "char": # type: ignore[call-overload] v = [y.rstrip() for y in vec] if self._encoding is not None: @@ -483,7 +536,12 @@ def read(self, nrows=None): df[x] = v if self._index is None: - df.index = range(self._lines_read, self._lines_read + read_lines) + # pandas\io\sas\sas_xport.py:486: error: Incompatible types in + # assignment (expression has type "range", variable has type + # "Index") [assignment] + df.index = range( # type: ignore[assignment] + self._lines_read, self._lines_read + read_lines + ) else: df = df.set_index(self._index) diff --git a/pandas/io/stata.py b/pandas/io/stata.py index d36bd42e7da8d..e1e30d1f6d200 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -367,8 +367,12 @@ def parse_dates_safe(dates, delta=False, year=False, days=False): d["delta"] = time_delta._values.astype(np.int64) // 1000 # microseconds if days or year: date_index = DatetimeIndex(dates) - d["year"] = date_index.year - d["month"] = date_index.month + # pandas\io\stata.py:370: error: "DatetimeIndex" has no + # attribute "year" [attr-defined] + d["year"] = date_index.year # type: ignore[attr-defined] + # pandas\io\stata.py:371: error: "DatetimeIndex" has no + # attribute "month" [attr-defined] + d["month"] = date_index.month # type: ignore[attr-defined] if days: days_in_ns = dates.astype(np.int64) - to_datetime( d["year"], format="%Y" @@ -876,7 +880,9 @@ def __init__(self): (65530, np.int8), ] ) - self.TYPE_MAP = list(range(251)) + list("bhlfd") + # pandas\io\stata.py:879: error: Argument 1 to "list" has incompatible + # type "str"; expected "Iterable[int]" [arg-type] + self.TYPE_MAP = list(range(251)) + list("bhlfd") # type: ignore[arg-type] self.TYPE_MAP_XML = dict( [ # Not really a Q, unclear how to handle byteswap @@ -1389,7 +1395,11 @@ def _setup_dtype(self) -> np.dtype: dtypes = [] # Convert struct data types to numpy data type for i, typ in enumerate(self.typlist): if typ in self.NUMPY_TYPE_MAP: - dtypes.append(("s" + str(i), self.byteorder + self.NUMPY_TYPE_MAP[typ])) + # pandas\io\stata.py:1392: error: Invalid index type + # "Union[int, str]" for "Dict[str, str]"; expected type "str" + # [index] + tmp = self.NUMPY_TYPE_MAP[typ] # type: ignore[index] + dtypes.append(("s" + str(i), self.byteorder + tmp)) else: dtypes.append(("s" + str(i), "S" + str(typ))) self._dtype = np.dtype(dtypes) @@ -1699,7 +1709,10 @@ def _do_convert_missing(self, data: DataFrame, convert_missing: bool) -> DataFra if fmt not in self.VALID_RANGE: continue - nmin, nmax = self.VALID_RANGE[fmt] + # pandas\io\stata.py:1702: error: Invalid index type "Union[int, + # str]" for "Dict[str, Tuple[Any, Any]]"; expected type "str" + # [index] + nmin, nmax = self.VALID_RANGE[fmt] # type: ignore[index] series = data[colname] missing = np.logical_or(series < nmin, series > nmax) diff --git a/setup.cfg b/setup.cfg index a3a948de8b925..91e6a4282177a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -136,38 +136,6 @@ check_untyped_defs=False [mypy-pandas.io.clipboard] check_untyped_defs=False -[mypy-pandas.io.excel._base] -check_untyped_defs=False - -[mypy-pandas.io.formats.console] -check_untyped_defs=False - -[mypy-pandas.io.formats.excel] -check_untyped_defs=False - -[mypy-pandas.io.formats.format] -check_untyped_defs=False - -[mypy-pandas.io.formats.style] -check_untyped_defs=False - -[mypy-pandas.io.json._json] -check_untyped_defs=False - -[mypy-pandas.io.parsers] -check_untyped_defs=False - -[mypy-pandas.io.pytables] -check_untyped_defs=False - -[mypy-pandas.io.sas.sas_xport] -check_untyped_defs=False - -[mypy-pandas.io.sas.sas7bdat] -check_untyped_defs=False - -[mypy-pandas.io.stata] -check_untyped_defs=False [mypy-pandas.plotting._matplotlib.converter] check_untyped_defs=False From dcbab319d5ad2b941df8287f6b3dd25deaf35eb5 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 9 Oct 2020 20:14:41 +0100 Subject: [PATCH 32/45] plotting --- pandas/plotting/_matplotlib/converter.py | 17 +++- pandas/plotting/_matplotlib/core.py | 101 ++++++++++++++++++----- pandas/plotting/_misc.py | 4 +- pandas/util/_decorators.py | 5 +- setup.cfg | 13 --- 5 files changed, 101 insertions(+), 39 deletions(-) diff --git a/pandas/plotting/_matplotlib/converter.py b/pandas/plotting/_matplotlib/converter.py index 3db7c38eced65..de76dad72004a 100644 --- a/pandas/plotting/_matplotlib/converter.py +++ b/pandas/plotting/_matplotlib/converter.py @@ -573,7 +573,9 @@ def first_label(label_flags): month_start = period_break(dates_, "month") def _hour_finder(label_interval, force_year_start): - _hour = dates_.hour + # pandas\plotting\_matplotlib\converter.py:576: error: + # "PeriodIndex" has no attribute "hour" [attr-defined] + _hour = dates_.hour # type: ignore[attr-defined] _prev_hour = (dates_ - 1 * dates_.freq).hour hour_start = (_hour - _prev_hour) != 0 info_maj[day_start] = True @@ -587,7 +589,9 @@ def _hour_finder(label_interval, force_year_start): def _minute_finder(label_interval): hour_start = period_break(dates_, "hour") - _minute = dates_.minute + # pandas\plotting\_matplotlib\converter.py:590: error: + # "PeriodIndex" has no attribute "minute" [attr-defined] + _minute = dates_.minute # type: ignore[attr-defined] _prev_minute = (dates_ - 1 * dates_.freq).minute minute_start = (_minute - _prev_minute) != 0 info_maj[hour_start] = True @@ -600,7 +604,9 @@ def _minute_finder(label_interval): def _second_finder(label_interval): minute_start = period_break(dates_, "minute") - _second = dates_.second + # pandas\plotting\_matplotlib\converter.py:603: error: + # "PeriodIndex" has no attribute "second" [attr-defined] + _second = dates_.second # type: ignore[attr-defined] _prev_second = (dates_ - 1 * dates_.freq).second second_start = (_second - _prev_second) != 0 info["maj"][minute_start] = True @@ -1019,7 +1025,10 @@ def _set_default_format(self, vmin, vmax): format = np.compress(info["min"] & np.logical_not(info["maj"]), info) else: format = np.compress(info["maj"], info) - self.formatdict = {x: f for (x, _, _, f) in format} + # pandas\plotting\_matplotlib\converter.py:1022: error: Incompatible + # types in assignment (expression has type "Dict[Any, Any]", variable + # has type "None") [assignment] + self.formatdict = {x: f for (x, _, _, f) in format} # type: ignore[assignment] return self.formatdict def set_locs(self, locs): diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index f806325d60eca..a1691826ba73c 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -277,7 +277,9 @@ def generate(self): self._make_legend() self._adorn_subplots() - for ax in self.axes: + # pandas\plotting\_matplotlib\core.py:280: error: "None" has no + # attribute "__iter__" (not iterable) [attr-defined] + for ax in self.axes: # type: ignore[attr-defined] self._post_plot_logic_common(ax, self.data) self._post_plot_logic(ax, self.data) @@ -367,7 +369,9 @@ def result(self): """ if self.subplots: if self.layout is not None and not is_list_like(self.ax): - return self.axes.reshape(*self.layout) + # pandas\plotting\_matplotlib\core.py:370: error: "None" has no + # attribute "reshape" [attr-defined] + return self.axes.reshape(*self.layout) # type: ignore[attr-defined] else: return self.axes else: @@ -377,9 +381,16 @@ def result(self): ) if sec_true or all_sec: # if all data is plotted on secondary, return right axes - return self._get_ax_layer(self.axes[0], primary=False) + + # pandas\plotting\_matplotlib\core.py:380: error: Value of type + # "None" is not indexable [index] + return self._get_ax_layer( + self.axes[0], primary=False # type: ignore[index] + ) else: - return self.axes[0] + # pandas\plotting\_matplotlib\core.py:382: error: Value of type + # "None" is not indexable [index] + return self.axes[0] # type: ignore[index] def _compute_plot_data(self): data = self.data @@ -466,7 +477,9 @@ def _post_plot_logic(self, ax, data): def _adorn_subplots(self): """Common post process unrelated to data""" - if len(self.axes) > 0: + # pandas\plotting\_matplotlib\core.py:469: error: Argument 1 to "len" + # has incompatible type "None"; expected "Sized" [arg-type] + if len(self.axes) > 0: # type: ignore[arg-type] all_axes = self._get_subplots() nrows, ncols = self._get_axes_layout() handle_shared_axes( @@ -479,7 +492,9 @@ def _adorn_subplots(self): sharey=self.sharey, ) - for ax in self.axes: + # pandas\plotting\_matplotlib\core.py:482: error: "None" has no + # attribute "__iter__" (not iterable) [attr-defined] + for ax in self.axes: # type: ignore[attr-defined] if self.yticks is not None: ax.set_yticks(self.yticks) @@ -511,7 +526,12 @@ def _adorn_subplots(self): f"number of columns = {self.nseries}" ) - for (ax, title) in zip(self.axes, self.title): + # pandas\plotting\_matplotlib\core.py:514: error: No + # overload variant of "zip" matches argument types "None", + # "Any" [call-overload] + for (ax, title) in zip( + self.axes, self.title # type: ignore[call-overload] + ): ax.set_title(title) else: self.fig.suptitle(self.title) @@ -522,7 +542,9 @@ def _adorn_subplots(self): "unless `subplots=True` is passed" ) raise ValueError(msg) - self.axes[0].set_title(self.title) + # pandas\plotting\_matplotlib\core.py:525: error: Value of type + # "None" is not indexable [index] + self.axes[0].set_title(self.title) # type: ignore[index] def _apply_axis_properties(self, axis: "Axis", rot=None, fontsize=None): """ @@ -560,7 +582,11 @@ def _add_legend_handle(self, handle, label, index=None): self.legend_labels.append(label) def _make_legend(self): - ax, leg, handle = self._get_ax_legend_handle(self.axes[0]) + # pandas\plotting\_matplotlib\core.py:563: error: Value of type "None" + # is not indexable [index] + ax, leg, handle = self._get_ax_legend_handle( + self.axes[0] # type: ignore[index] + ) handles = [] labels = [] @@ -575,8 +601,20 @@ def _make_legend(self): if self.legend: if self.legend == "reverse": - self.legend_handles = reversed(self.legend_handles) - self.legend_labels = reversed(self.legend_labels) + # pandas\plotting\_matplotlib\core.py:578: error: + # Incompatible types in assignment (expression has type + # "Iterator[Any]", variable has type "List[Any]") + # [assignment] + self.legend_handles = reversed( # type: ignore[assignment] + self.legend_handles + ) + # pandas\plotting\_matplotlib\core.py:579: error: + # Incompatible types in assignment (expression has type + # "Iterator[Optional[Hashable]]", variable has type + # "List[Optional[Hashable]]") [assignment] + self.legend_labels = reversed( # type: ignore[assignment] + self.legend_labels + ) handles += self.legend_handles labels += self.legend_labels @@ -588,7 +626,9 @@ def _make_legend(self): ax.legend(handles, labels, loc="best", title=title) elif self.subplots and self.legend: - for ax in self.axes: + # pandas\plotting\_matplotlib\core.py:591: error: "None" has no + # attribute "__iter__" (not iterable) [attr-defined] + for ax in self.axes: # type: ignore[attr-defined] if ax.get_visible(): ax.legend(loc="best") @@ -700,11 +740,17 @@ def _get_ax_layer(cls, ax, primary=True): def _get_ax(self, i): # get the twinx ax if appropriate if self.subplots: - ax = self.axes[i] + # pandas\plotting\_matplotlib\core.py:703: error: Value of type + # "None" is not indexable [index] + ax = self.axes[i] # type: ignore[index] ax = self._maybe_right_yaxis(ax, i) - self.axes[i] = ax + # pandas\plotting\_matplotlib\core.py:705: error: Unsupported + # target for indexed assignment ("None") [index] + self.axes[i] = ax # type: ignore[index] else: - ax = self.axes[0] + # pandas\plotting\_matplotlib\core.py:707: error: Value of type + # "None" is not indexable [index] + ax = self.axes[0] # type: ignore[index] ax = self._maybe_right_yaxis(ax, i) ax.get_yaxis().set_visible(True) @@ -875,7 +921,11 @@ def _get_subplots(self): from matplotlib.axes import Subplot return [ - ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot) + # pandas\plotting\_matplotlib\core.py:878: error: Value of type + # "None" is not indexable [index] + ax + for ax in self.axes[0].get_figure().get_axes() # type: ignore[index] + if isinstance(ax, Subplot) ] def _get_axes_layout(self) -> Tuple[int, int]: @@ -982,7 +1032,9 @@ def __init__(self, data, x, y, s=None, c=None, **kwargs): def _make_plot(self): x, y, c, data = self.x, self.y, self.c, self.data - ax = self.axes[0] + # pandas\plotting\_matplotlib\core.py:985: error: Value of type "None" + # is not indexable [index] + ax = self.axes[0] # type: ignore[index] c_is_column = is_hashable(c) and c in self.data.columns @@ -1047,7 +1099,9 @@ def __init__(self, data, x, y, C=None, **kwargs): def _make_plot(self): x, y, data, C = self.x, self.y, self.data, self.C - ax = self.axes[0] + # pandas\plotting\_matplotlib\core.py:1050: error: Value of type "None" + # is not indexable [index] + ax = self.axes[0] # type: ignore[index] # pandas uses colormap, matplotlib uses cmap. cmap = self.colormap or "BuGn" cmap = self.plt.cm.get_cmap(cmap) @@ -1097,7 +1151,11 @@ def _make_plot(self): it = self._iter_data(data=data, keep_index=True) else: x = self._get_xticks(convert_period=True) - plotf = self._plot + # pandas\plotting\_matplotlib\core.py:1100: error: Incompatible + # types in assignment (expression has type "Callable[[Any, Any, + # Any, Any, Any, Any, KwArg(Any)], Any]", variable has type + # "Callable[[Any, Any, Any, Any, KwArg(Any)], Any]") [assignment] + plotf = self._plot # type: ignore[assignment] it = self._iter_data() stacking_id = self._get_stacking_id() @@ -1543,7 +1601,10 @@ def blank_labeler(label, value): if labels is not None: blabels = [blank_labeler(l, value) for l, value in zip(labels, y)] else: - blabels = None + # pandas\plotting\_matplotlib\core.py:1546: error: Incompatible + # types in assignment (expression has type "None", variable has + # type "List[Any]") [assignment] + blabels = None # type: ignore[assignment] results = ax.pie(y, labels=blabels, **kwds) if kwds.get("autopct", None) is not None: diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 6e473bf5b182c..58f44104b99d6 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -530,7 +530,9 @@ def reset(self): ------- None """ - self.__init__() + # pandas\plotting\_misc.py:533: error: Cannot access "__init__" + # directly [misc] + self.__init__() # type: ignore[misc] def _get_canonical_key(self, key): return self._ALIASES.get(key, key) diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index f81bca7e85156..1559106703a18 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -278,7 +278,10 @@ def decorate(func): allow_args = allowed_args else: spec = inspect.getfullargspec(func) - allow_args = spec.args[: -len(spec.defaults)] + # pandas\util\_decorators.py:281: error: Argument 1 to "len" has + # incompatible type "Optional[Tuple[Any, ...]]"; expected "Sized" + # [arg-type] + allow_args = spec.args[: -len(spec.defaults)] # type: ignore[arg-type] @wraps(func) def wrapper(*args, **kwargs): diff --git a/setup.cfg b/setup.cfg index 91e6a4282177a..5a42f5374fe4b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -135,16 +135,3 @@ check_untyped_defs=False [mypy-pandas.io.clipboard] check_untyped_defs=False - - -[mypy-pandas.plotting._matplotlib.converter] -check_untyped_defs=False - -[mypy-pandas.plotting._matplotlib.core] -check_untyped_defs=False - -[mypy-pandas.plotting._misc] -check_untyped_defs=False - -[mypy-pandas.util._decorators] -check_untyped_defs=False From 3100ad67482660d11bd7cf4f3c19c58d10802ed4 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 10 Oct 2020 11:44:23 +0100 Subject: [PATCH 33/45] add ignore after merge master --- pandas/core/window/rolling.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 922de95c28b74..4fddcb609b7be 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1366,7 +1366,9 @@ def apply( def _generate_cython_apply_func(self, args, kwargs, raw, func): from pandas import Series - window_func = partial( + # pandas\core\window\rolling.py:1369: error: "partial" gets multiple + # values for keyword argument "func" [misc] + window_func = partial( # type: ignore[misc] self._get_roll_func("roll_apply"), args=args, kwargs=kwargs, From 8760bbc3d1f89733062b1d8038a01365abdae9cb Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 10 Oct 2020 12:01:11 +0100 Subject: [PATCH 34/45] remove unused 'type: ignore' comments --- pandas/io/json/_json.py | 14 +++----------- pandas/plotting/_matplotlib/converter.py | 5 +---- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index 4872ffd459341..3cf3c2e7fd91d 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -904,11 +904,7 @@ def check_keys_split(self, decoded): """ Checks that dict has only the appropriate keys for orient='split'. """ - # pandas\io\json\_json.py:903: error: "Parser" has no attribute - # "_split_keys" [attr-defined] - bad_keys = set(decoded.keys()).difference( - set(self._split_keys) # type: ignore[attr-defined] - ) + bad_keys = set(decoded.keys()).difference(set(self._split_keys)) if bad_keys: bad_keys_joined = ", ".join(bad_keys) raise ValueError(f"JSON data had unexpected key(s): {bad_keys_joined}") @@ -918,14 +914,10 @@ def parse(self): # try numpy numpy = self.numpy if numpy: - # pandas\io\json\_json.py:913: error: "Parser" has no attribute - # "_parse_numpy" [attr-defined] - self._parse_numpy() # type: ignore[attr-defined] + self._parse_numpy() else: - # pandas\io\json\_json.py:916: error: "Parser" has no attribute - # "_parse_no_numpy" [attr-defined] - self._parse_no_numpy() # type: ignore[attr-defined] + self._parse_no_numpy() if self.obj is None: return None diff --git a/pandas/plotting/_matplotlib/converter.py b/pandas/plotting/_matplotlib/converter.py index babc4aeda4dda..ce7d69dea6c4f 100644 --- a/pandas/plotting/_matplotlib/converter.py +++ b/pandas/plotting/_matplotlib/converter.py @@ -1025,10 +1025,7 @@ def _set_default_format(self, vmin, vmax): format = np.compress(info["min"] & np.logical_not(info["maj"]), info) else: format = np.compress(info["maj"], info) - # pandas\plotting\_matplotlib\converter.py:1022: error: Incompatible - # types in assignment (expression has type "Dict[Any, Any]", variable - # has type "None") [assignment] - self.formatdict = {x: f for (x, _, _, f) in format} # type: ignore[assignment] + self.formatdict = {x: f for (x, _, _, f) in format} return self.formatdict def set_locs(self, locs): From c0bcd340adc70e2bbf22b0b967a731b968b4d330 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 12 Oct 2020 14:50:09 +0100 Subject: [PATCH 35/45] remove unused 'type: ignore' comments --- pandas/core/arrays/datetimelike.py | 71 ++++---------------------- pandas/core/arrays/string_.py | 18 +++++-- pandas/core/generic.py | 80 ++++++++++++++++++++--------- pandas/core/indexes/base.py | 45 ++++------------- pandas/core/indexes/multi.py | 81 +++++++----------------------- pandas/core/internals/blocks.py | 27 ++-------- pandas/io/formats/format.py | 11 +++- pandas/io/sas/sas7bdat.py | 66 ++++-------------------- pandas/io/sas/sas_xport.py | 52 ++++--------------- 9 files changed, 140 insertions(+), 311 deletions(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 85ce929a72ab0..d1c7afaa3641f 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -376,12 +376,7 @@ def astype(self, dtype, copy=True): def view(self, dtype=None): if dtype is None or dtype is self.dtype: - # pandas\core\arrays\datetimelike.py:632: error: Too many arguments for - # "DatetimeLikeArrayMixin" [call-arg] - - # pandas\core\arrays\datetimelike.py:632: error: Unexpected keyword - # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] - return type(self)(self._ndarray, dtype=self.dtype) # type: ignore[call-arg] + return type(self)(self._ndarray, dtype=self.dtype) return self._ndarray.view(dtype=dtype) # ------------------------------------------------------------------ @@ -420,12 +415,7 @@ def _values_for_factorize(self): @classmethod def _from_factorized(cls, values, original): - # pandas\core\arrays\datetimelike.py:671: error: Too many arguments for - # "DatetimeLikeArrayMixin" [call-arg] - - # pandas\core\arrays\datetimelike.py:671: error: Unexpected keyword - # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] - return cls(values, dtype=original.dtype) # type: ignore[call-arg] + return cls(values, dtype=original.dtype) # ------------------------------------------------------------------ # Validation Methods @@ -682,13 +672,8 @@ def value_counts(self, dropna=False): cls = type(self) result = value_counts(values, sort=False, dropna=dropna) - # pandas\core\arrays\datetimelike.py:931: error: Too many arguments - # for "DatetimeLikeArrayMixin" [call-arg] - - # pandas\core\arrays\datetimelike.py:931: error: Unexpected keyword - # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] index = Index( - cls(result.index.view("i8"), dtype=self.dtype), # type: ignore[call-arg] + cls(result.index.view("i8"), dtype=self.dtype), name=result.index.name, ) return Series(result._values, index=index, name=result.name) @@ -823,10 +808,7 @@ def _validate_frequency(cls, index, freq, **kwargs): return None try: - # pandas\core\arrays\datetimelike.py:1065: error: - # "Type[DatetimeLikeArrayMixin]" has no attribute "_generate_range" - # [attr-defined] - on_freq = cls._generate_range( # type: ignore[attr-defined] + on_freq = cls._generate_range( start=index[0], end=None, periods=len(index), freq=freq, **kwargs ) if not np.array_equal(index.asi8, on_freq.asi8): @@ -949,12 +931,7 @@ def _add_timedeltalike_scalar(self, other): new_values = np.empty(self.shape, dtype="i8") new_values[:] = iNaT - # pandas\core\arrays\datetimelike.py:1155: error: Too many - # arguments for "DatetimeLikeArrayMixin" [call-arg] - - # pandas\core\arrays\datetimelike.py:1155: error: Unexpected - # keyword argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] - return type(self)(new_values, dtype=self.dtype) # type: ignore[call-arg] + return type(self)(new_values, dtype=self.dtype) inc = delta_to_nanoseconds(other) new_values = checked_add_with_arr(self.asi8, inc, arr_mask=self._isnan).view( @@ -967,17 +944,7 @@ def _add_timedeltalike_scalar(self, other): # adding a scalar preserves freq new_freq = self.freq - # pandas\core\arrays\datetimelike.py:1168: error: Too many arguments - # for "DatetimeLikeArrayMixin" [call-arg] - - # pandas\core\arrays\datetimelike.py:1168: error: Unexpected keyword - # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] - - # pandas\core\arrays\datetimelike.py:1168: error: Unexpected keyword - # argument "freq" for "DatetimeLikeArrayMixin" [call-arg] - return type(self)( # type: ignore[call-arg] - new_values, dtype=self.dtype, freq=new_freq - ) + return type(self)(new_values, dtype=self.dtype, freq=new_freq) def _add_timedelta_arraylike(self, other): """ @@ -1007,12 +974,7 @@ def _add_timedelta_arraylike(self, other): mask = self._isnan | other._isnan new_values[mask] = iNaT - # pandas\core\arrays\datetimelike.py:1198: error: Too many arguments - # for "DatetimeLikeArrayMixin" [call-arg] - - # pandas\core\arrays\datetimelike.py:1198: error: Unexpected keyword - # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] - return type(self)(new_values, dtype=self.dtype) # type: ignore[call-arg] + return type(self)(new_values, dtype=self.dtype) def _add_nat(self): """ @@ -1027,16 +989,7 @@ def _add_nat(self): # and datetime dtypes result = np.zeros(self.shape, dtype=np.int64) result.fill(iNaT) - - # pandas\core\arrays\datetimelike.py:1213: error: Too many arguments - # for "DatetimeLikeArrayMixin" [call-arg] - - # pandas\core\arrays\datetimelike.py:1213: error: Unexpected keyword - # argument "dtype" for "DatetimeLikeArrayMixin" [call-arg] - - # pandas\core\arrays\datetimelike.py:1213: error: Unexpected keyword - # argument "freq" for "DatetimeLikeArrayMixin" [call-arg] - return type(self)(result, dtype=self.dtype, freq=None) # type: ignore[call-arg] + return type(self)(result, dtype=self.dtype, freq=None) def _sub_nat(self): """ @@ -1126,13 +1079,7 @@ def _time_shift(self, periods, freq=None): # Note: in the DatetimeTZ case, _generate_range will infer the # appropriate timezone from `start` and `end`, so tz does not need # to be passed explicitly. - - # pandas\core\arrays\datetimelike.py:1303: error: - # "DatetimeLikeArrayMixin" has no attribute "_generate_range" - # [attr-defined] - return self._generate_range( # type: ignore[attr-defined] - start=start, end=end, periods=None, freq=self.freq - ) + return self._generate_range(start=start, end=end, periods=None, freq=self.freq) @unpack_zerodim_and_defer("__add__") def __add__(self, other): diff --git a/pandas/core/arrays/string_.py b/pandas/core/arrays/string_.py index 466f1392a85cc..dcb503dabafdc 100644 --- a/pandas/core/arrays/string_.py +++ b/pandas/core/arrays/string_.py @@ -362,11 +362,19 @@ def method(self, other): @classmethod def _add_arithmetic_ops(cls): - cls.__add__ = cls._create_arithmetic_method(operator.add) - cls.__radd__ = cls._create_arithmetic_method(ops.radd) - - cls.__mul__ = cls._create_arithmetic_method(operator.mul) - cls.__rmul__ = cls._create_arithmetic_method(ops.rmul) + cls.__add__ = cls._create_arithmetic_method( # type: ignore[assignment] + operator.add + ) + cls.__radd__ = cls._create_arithmetic_method( # type: ignore[assignment] + ops.radd + ) + + cls.__mul__ = cls._create_arithmetic_method( # type: ignore[assignment] + operator.mul + ) + cls.__rmul__ = cls._create_arithmetic_method( # type: ignore[assignment] + ops.rmul + ) # ------------------------------------------------------------------------ # String methods interface diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2703457f42787..50db7e6092b95 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3117,10 +3117,7 @@ def to_latex( self = cast("DataFrame", self) formatter = DataFrameFormatter( - # pandas\core\generic.py:3116: error: Argument 1 to - # "DataFrameFormatter" has incompatible type "NDFrame"; expected - # "DataFrame" [arg-type] - self, # type: ignore[arg-type] + self, columns=columns, col_space=col_space, na_rep=na_rep, @@ -10716,7 +10713,14 @@ def _add_numeric_operations(cls): def any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): return NDFrame.all(self, axis, bool_only, skipna, level, **kwargs) - cls.all = all + # pandas\core\generic.py:10719: error: Cannot assign to a method + # [assignment] + + # pandas\core\generic.py:10719: error: Incompatible types in assignment + # (expression has type "Callable[[Iterable[object]], bool]", variable + # has type "Callable[[NDFrame, Any, Any, Any, Any, KwArg(Any)], Any]") + # [assignment] + cls.all = all # type: ignore[assignment] @doc( desc="Return the mean absolute deviation of the values " @@ -10731,9 +10735,9 @@ def any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): def mad(self, axis=None, skipna=None, level=None): return NDFrame.mad(self, axis, skipna, level) - # pandas\core\generic.py:10470: error: "Type[NDFrame]" has no attribute - # "mad" [attr-defined] - cls.mad = mad # type: ignore[attr-defined] + # pandas\core\generic.py:10736: error: Cannot assign to a method + # [assignment] + cls.mad = mad # type: ignore[assignment] @doc( _num_ddof_doc, @@ -10755,7 +10759,9 @@ def sem( ): return NDFrame.sem(self, axis, skipna, level, ddof, numeric_only, **kwargs) - cls.sem = sem + # pandas\core\generic.py:10758: error: Cannot assign to a method + # [assignment] + cls.sem = sem # type: ignore[assignment] @doc( _num_ddof_doc, @@ -10776,7 +10782,9 @@ def var( ): return NDFrame.var(self, axis, skipna, level, ddof, numeric_only, **kwargs) - cls.var = var + # pandas\core\generic.py:10779: error: Cannot assign to a method + # [assignment] + cls.var = var # type: ignore[assignment] @doc( _num_ddof_doc, @@ -10798,7 +10806,9 @@ def std( ): return NDFrame.std(self, axis, skipna, level, ddof, numeric_only, **kwargs) - cls.std = std + # pandas\core\generic.py:10801: error: Cannot assign to a method + # [assignment] + cls.std = std # type: ignore[assignment] @doc( _cnum_doc, @@ -10812,7 +10822,9 @@ def std( def cummin(self, axis=None, skipna=True, *args, **kwargs): return NDFrame.cummin(self, axis, skipna, *args, **kwargs) - cls.cummin = cummin + # pandas\core\generic.py:10815: error: Cannot assign to a method + # [assignment] + cls.cummin = cummin # type: ignore[assignment] @doc( _cnum_doc, @@ -10826,7 +10838,9 @@ def cummin(self, axis=None, skipna=True, *args, **kwargs): def cummax(self, axis=None, skipna=True, *args, **kwargs): return NDFrame.cummax(self, axis, skipna, *args, **kwargs) - cls.cummax = cummax + # pandas\core\generic.py:10829: error: Cannot assign to a method + # [assignment] + cls.cummax = cummax # type: ignore[assignment] @doc( _cnum_doc, @@ -10840,7 +10854,9 @@ def cummax(self, axis=None, skipna=True, *args, **kwargs): def cumsum(self, axis=None, skipna=True, *args, **kwargs): return NDFrame.cumsum(self, axis, skipna, *args, **kwargs) - cls.cumsum = cumsum + # pandas\core\generic.py:10843: error: Cannot assign to a method + # [assignment] + cls.cumsum = cumsum # type: ignore[assignment] @doc( _cnum_doc, @@ -10854,7 +10870,9 @@ def cumsum(self, axis=None, skipna=True, *args, **kwargs): def cumprod(self, axis=None, skipna=True, *args, **kwargs): return NDFrame.cumprod(self, axis, skipna, *args, **kwargs) - cls.cumprod = cumprod + # pandas\core\generic.py:10857: error: Cannot assign to a method + # [assignment] + cls.cumprod = cumprod # type: ignore[assignment] @doc( _num_doc, @@ -10880,7 +10898,9 @@ def sum( self, axis, skipna, level, numeric_only, min_count, **kwargs ) - cls.sum = sum + # pandas\core\generic.py:10883: error: Cannot assign to a method + # [assignment] + cls.sum = sum # type: ignore[assignment] @doc( _num_doc, @@ -10905,7 +10925,9 @@ def prod( self, axis, skipna, level, numeric_only, min_count, **kwargs ) - cls.prod = prod + # pandas\core\generic.py:10908: error: Cannot assign to a method + # [assignment] + cls.prod = prod # type: ignore[assignment] cls.product = prod @doc( @@ -10921,7 +10943,9 @@ def prod( def mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.mean(self, axis, skipna, level, numeric_only, **kwargs) - cls.mean = mean + # pandas\core\generic.py:10924: error: Cannot assign to a method + # [assignment] + cls.mean = mean # type: ignore[assignment] @doc( _num_doc, @@ -10936,7 +10960,9 @@ def mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): def skew(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.skew(self, axis, skipna, level, numeric_only, **kwargs) - cls.skew = skew + # pandas\core\generic.py:10939: error: Cannot assign to a method + # [assignment] + cls.skew = skew # type: ignore[assignment] @doc( _num_doc, @@ -10954,7 +10980,9 @@ def skew(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): def kurt(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.kurt(self, axis, skipna, level, numeric_only, **kwargs) - cls.kurt = kurt + # pandas\core\generic.py:10957: error: Cannot assign to a method + # [assignment] + cls.kurt = kurt # type: ignore[assignment] cls.kurtosis = kurt @doc( @@ -10972,7 +11000,9 @@ def median( ): return NDFrame.median(self, axis, skipna, level, numeric_only, **kwargs) - cls.median = median + # pandas\core\generic.py:10975: error: Cannot assign to a method + # [assignment] + cls.median = median # type: ignore[assignment] @doc( _num_doc, @@ -10989,7 +11019,9 @@ def median( def max(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.max(self, axis, skipna, level, numeric_only, **kwargs) - cls.max = max + # pandas\core\generic.py:10992: error: Cannot assign to a method + # [assignment] + cls.max = max # type: ignore[assignment] @doc( _num_doc, @@ -11006,7 +11038,9 @@ def max(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): def min(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.min(self, axis, skipna, level, numeric_only, **kwargs) - cls.min = min + # pandas\core\generic.py:11009: error: Cannot assign to a method + # [assignment] + cls.min = min # type: ignore[assignment] @doc(Rolling) def rolling( diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 9e35094208aac..de3ff55aaf027 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -940,10 +940,7 @@ def _format_attrs(self): """ Return a list of tuples of the (attr,formatted_value). """ - # pandas\core\indexes\base.py:969: error: Argument 1 to - # "format_object_attrs" has incompatible type "Index"; expected - # "Sequence[Any]" [arg-type] - return format_object_attrs(self) # type: ignore[arg-type] + return format_object_attrs(self) def _mpl_repr(self): # how to represent ourselves to matplotlib @@ -1581,12 +1578,8 @@ def droplevel(self, level=0): # The two checks above guarantee that here self is a MultiIndex self = cast("MultiIndex", self) - # pandas\core\indexes\base.py:1606: error: "Index" has no attribute - # "levels"; maybe "nlevels"? [attr-defined] - new_levels = list(self.levels) # type: ignore[attr-defined] - # pandas\core\indexes\base.py:1607: error: "Index" has no attribute - # "codes" [attr-defined] - new_codes = list(self.codes) # type: ignore[attr-defined] + new_levels = list(self.levels) + new_codes = list(self.codes) new_names = list(self.names) for i in levnums: @@ -3747,9 +3740,7 @@ def _get_leaf_sorter(labels): assert isinstance(left, MultiIndex) level = left._get_level_number(level) - # pandas\core\indexes\base.py:3757: error: "Index" has no attribute - # "levels"; maybe "nlevels"? [attr-defined] - old_level = left.levels[level] # type: ignore[attr-defined] + old_level = left.levels[level] if not right.is_unique: raise NotImplementedError( @@ -3765,10 +3756,8 @@ def _get_leaf_sorter(labels): left_indexer = None join_index = left else: # sort the leaves - # pandas\core\indexes\base.py:3773: error: "Index" has no - # attribute "codes" [attr-defined] left_indexer = _get_leaf_sorter( - left.codes[: level + 1] # type: ignore[attr-defined] + left.codes[: level + 1] ) join_index = left[left_indexer] @@ -3776,22 +3765,16 @@ def _get_leaf_sorter(labels): left_lev_indexer = ensure_int64(left_lev_indexer) rev_indexer = lib.get_reverse_indexer(left_lev_indexer, len(old_level)) - # pandas\core\indexes\base.py:3781: error: "Index" has no attribute - # "codes" [attr-defined] new_lev_codes = algos.take_nd( rev_indexer, - left.codes[level], # type: ignore[attr-defined] - allow_fill=False, + left.codes[level], + allow_fill=False ) - # pandas\core\indexes\base.py:3784: error: "Index" has no attribute - # "codes" [attr-defined] - new_codes = list(left.codes) # type: ignore[attr-defined] + new_codes = list(left.codes) new_codes[level] = new_lev_codes - # pandas\core\indexes\base.py:3787: error: "Index" has no attribute - # "levels"; maybe "nlevels"? [attr-defined] - new_levels = list(left.levels) # type: ignore[attr-defined] + new_levels = list(left.levels) new_levels[level] = new_level if keep_order: # just drop missing values. o.w. keep order @@ -3834,17 +3817,11 @@ def _get_leaf_sorter(labels): ) if right_lev_indexer is not None: - # pandas\core\indexes\base.py:3831: error: "Index" has no attribute - # "codes" [attr-defined] right_indexer = algos.take_nd( - right_lev_indexer, - join_index.codes[level], # type: ignore[attr-defined] - allow_fill=False, + right_lev_indexer, join_index.codes[level], allow_fill=False ) else: - # pandas\core\indexes\base.py:3834: error: "Index" has no attribute - # "codes" [attr-defined] - right_indexer = join_index.codes[level] # type: ignore[attr-defined] + right_indexer = join_index.codes[level] if flip_order: left_indexer, right_indexer = right_indexer, left_indexer diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index c62a0afc71b80..3e13bcf902cf6 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1279,10 +1279,7 @@ def _format_attrs(self): """ Return a list of tuples of the (attr,formatted_value). """ - # pandas\core\indexes\multi.py:1280: error: Argument 1 to - # "format_object_attrs" has incompatible type "MultiIndex"; expected - # "Sequence[Any]" [arg-type] - return format_object_attrs(self, include_dtype=False) # type: ignore[arg-type] + return format_object_attrs(self, include_dtype=False) def _format_native_types(self, na_rep="nan", **kwargs): new_levels = [] @@ -3703,23 +3700,11 @@ def _add_numeric_methods_add_sub_disabled(cls): """ Add in the numeric add/sub methods to disable. """ - # pandas\core\indexes\multi.py:3694: error: Unsupported left operand - # type for + ("Type[MultiIndex]") [operator] - cls.__add__ = make_invalid_op("__add__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3695: error: "Type[MultiIndex]" has no - # attribute "__radd__" [attr-defined] - cls.__radd__ = make_invalid_op("__radd__") # type: ignore[attr-defined] - # pandas\core\indexes\multi.py:3696: error: Cannot assign to a method - # [assignment] + cls.__add__ = make_invalid_op("__add__") # type: ignore[assignment] + cls.__radd__ = make_invalid_op("__radd__") # type: ignore[assignment] cls.__iadd__ = make_invalid_op("__iadd__") # type: ignore[assignment] - # pandas\core\indexes\multi.py:3697: error: Unsupported left operand - # type for - ("Type[MultiIndex]") [operator] - cls.__sub__ = make_invalid_op("__sub__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3698: error: "Type[MultiIndex]" has no - # attribute "__rsub__" [attr-defined] - cls.__rsub__ = make_invalid_op("__rsub__") # type: ignore[attr-defined] - # pandas\core\indexes\multi.py:3699: error: "Type[MultiIndex]" has no - # attribute "__isub__" [attr-defined] + cls.__sub__ = make_invalid_op("__sub__") # type: ignore[assignment] + cls.__rsub__ = make_invalid_op("__rsub__") # type: ignore[assignment] cls.__isub__ = make_invalid_op("__isub__") # type: ignore[attr-defined] @classmethod @@ -3727,55 +3712,23 @@ def _add_numeric_methods_disabled(cls): """ Add in numeric methods to disable other than add/sub. """ - # pandas\core\indexes\multi.py:3706: error: Unsupported left operand - # type for ** ("Type[MultiIndex]") [operator] - cls.__pow__ = make_invalid_op("__pow__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3707: error: "Type[MultiIndex]" has no - # attribute "__rpow__" [attr-defined] - cls.__rpow__ = make_invalid_op("__rpow__") # type: ignore[attr-defined] - # pandas\core\indexes\multi.py:3708: error: Unsupported left operand - # type for * ("Type[MultiIndex]") [operator] - cls.__mul__ = make_invalid_op("__mul__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3709: error: "Type[MultiIndex]" has no - # attribute "__rmul__" [attr-defined] - cls.__rmul__ = make_invalid_op("__rmul__") # type: ignore[attr-defined] - # pandas\core\indexes\multi.py:3710: error: Unsupported left operand - # type for // ("Type[MultiIndex]") [operator] - cls.__floordiv__ = make_invalid_op("__floordiv__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3711: error: "Type[MultiIndex]" has no - # attribute "__rfloordiv__" [attr-defined] - cls.__rfloordiv__ = make_invalid_op( # type: ignore[attr-defined] + cls.__pow__ = make_invalid_op("__pow__") # type: ignore[assignment] + cls.__rpow__ = make_invalid_op("__rpow__") # type: ignore[assignment] + cls.__mul__ = make_invalid_op("__mul__") # type: ignore[assignment] + cls.__rmul__ = make_invalid_op("__rmul__") # type: ignore[assignment] + cls.__floordiv__ = make_invalid_op("__floordiv__") # type: ignore[assignment] + cls.__rfloordiv__ = make_invalid_op( # type: ignore[assignment] "__rfloordiv__" ) - # pandas\core\indexes\multi.py:3712: error: Unsupported left operand - # type for / ("Type[MultiIndex]") [operator] - cls.__truediv__ = make_invalid_op("__truediv__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3713: error: "Type[MultiIndex]" has no - # attribute "__rtruediv__" [attr-defined] - cls.__rtruediv__ = make_invalid_op("__rtruediv__") # type: ignore[attr-defined] - # pandas\core\indexes\multi.py:3714: error: Unsupported left operand - # type for % ("Type[MultiIndex]") [operator] - cls.__mod__ = make_invalid_op("__mod__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3715: error: "Type[MultiIndex]" has no - # attribute "__rmod__" [attr-defined] - cls.__rmod__ = make_invalid_op("__rmod__") # type: ignore[attr-defined] - # pandas\core\indexes\multi.py:3716: error: Unsupported left operand - # type for divmod ("Type[MultiIndex]") [operator] - cls.__divmod__ = make_invalid_op("__divmod__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3717: error: "Type[MultiIndex]" has no - # attribute "__rdivmod__" [attr-defined] - cls.__rdivmod__ = make_invalid_op("__rdivmod__") # type: ignore[attr-defined] - # pandas\core\indexes\multi.py:3718: error: Unsupported operand type - # for unary - ("Type[MultiIndex]") [operator] + cls.__truediv__ = make_invalid_op("__truediv__") # type: ignore[assignment] + cls.__rtruediv__ = make_invalid_op("__rtruediv__") # type: ignore[assignment] + cls.__mod__ = make_invalid_op("__mod__") # type: ignore[assignment] + cls.__rmod__ = make_invalid_op("__rmod__") # type: ignore[assignment] + cls.__divmod__ = make_invalid_op("__divmod__") # type: ignore[assignment] + cls.__rdivmod__ = make_invalid_op("__rdivmod__") # type: ignore[assignment] cls.__neg__ = make_invalid_op("__neg__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3719: error: Unsupported operand type - # for unary + ("Type[MultiIndex]") [operator] cls.__pos__ = make_invalid_op("__pos__") # type: ignore[operator] - # pandas\core\indexes\multi.py:3720: error: "Type[MultiIndex]" has no - # attribute "__abs__" [attr-defined] cls.__abs__ = make_invalid_op("__abs__") # type: ignore[attr-defined] - # pandas\core\indexes\multi.py:3721: error: "Type[MultiIndex]" has no - # attribute "__inv__" [attr-defined] cls.__inv__ = make_invalid_op("__inv__") # type: ignore[attr-defined] diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index fc7a3666daeb1..d197b7d08a0c2 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2098,35 +2098,20 @@ def get_values(self, dtype=None): """ if is_object_dtype(dtype): # DTA/TDA constructor and astype can handle 2D - - # pandas\core\internals\blocks.py:2090: error: - # "DatetimeLikeBlockMixin" has no attribute "values" - # [attr-defined] - return self._holder(self.values).astype( # type: ignore[attr-defined] - object - ) - # pandas\core\internals\blocks.py:2091: error: "DatetimeLikeBlockMixin" - # has no attribute "values" [attr-defined] - return self.values # type: ignore[attr-defined] + return self._holder(self.values).astype(object) + return self.values def internal_values(self): # Override to return DatetimeArray and TimedeltaArray return self.array_values() def array_values(self): - # pandas\core\internals\blocks.py:2098: error: "DatetimeLikeBlockMixin" - # has no attribute "values" [attr-defined] - return self._holder._simple_new(self.values) # type: ignore[attr-defined] + return self._holder._simple_new(self.values) def iget(self, key): # GH#31649 we need to wrap scalars in Timestamp/Timedelta # TODO(EA2D): this can be removed if we ever have 2D EA - - # pandas\core\internals\blocks.py:2103: error: "DatetimeLikeBlockMixin" - # has no attribute "shape" [attr-defined] - return self.array_values().reshape(self.shape)[ # type: ignore[attr-defined] - key - ] + return self.array_values().reshape(self.shape)[key] def diff(self, n: int, axis: int = 0) -> List["Block"]: """ @@ -2158,9 +2143,7 @@ def shift(self, periods, axis=0, fill_value=None): # TODO(EA2D) this is unnecessary if these blocks are backed by 2D EAs values = self.array_values() new_values = values.shift(periods, fill_value=fill_value, axis=axis) - # pandas\core\internals\blocks.py:2109: error: "DatetimeLikeBlockMixin" - # has no attribute "make_block_same_class" [attr-defined] - return self.make_block_same_class(new_values) # type: ignore[attr-defined] + return self.make_block_same_class(new_values) def to_native_types(self, na_rep="NaT", **kwargs): """ convert to our native types format """ diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 0804aa1be9b65..5cf4c4841f6e5 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1408,7 +1408,16 @@ def _value_formatter( def base_formatter(v): assert float_format is not None # for mypy - return float_format(value=v) if notna(v) else self.na_rep + # pandas\io\formats\format.py:1411: error: "str" not callable + # [operator] + + # pandas\io\formats\format.py:1411: error: Unexpected keyword + # argument "value" for "__call__" of "EngFormatter" [call-arg] + return ( + float_format(value=v) # type: ignore[operator,call-arg] + if notna(v) + else self.na_rep + ) else: diff --git a/pandas/io/sas/sas7bdat.py b/pandas/io/sas/sas7bdat.py index 79a452f881229..989036917b265 100644 --- a/pandas/io/sas/sas7bdat.py +++ b/pandas/io/sas/sas7bdat.py @@ -210,16 +210,8 @@ def close(self): def _get_properties(self): # Check magic number - - # pandas\io\sas\sas7bdat.py:176: error: Item "str" of "Union[str, - # IO[Any], IOBase]" has no attribute "seek" [union-attr] - self._path_or_buf.seek(0) # type: ignore[union-attr] - # pandas\io\sas\sas7bdat.py:177: error: Item "str" of "Union[str, - # IO[Any], IOBase]" has no attribute "read" [union-attr] - - # pandas\io\sas\sas7bdat.py:177: error: Item "IOBase" of "Union[str, - # IO[Any], IOBase]" has no attribute "read" [union-attr] - self._cached_page = self._path_or_buf.read(288) # type: ignore[union-attr] + self._path_or_buf.seek(0) + self._cached_page = self._path_or_buf.read(288) if self._cached_page[0 : len(const.magic)] != const.magic: self.close() raise ValueError("magic number mismatch (not a SAS file?)") @@ -294,15 +286,7 @@ def _get_properties(self): ) # Read the rest of the header into cached_page. - - # pandas\io\sas\sas7bdat.py:252: error: Item "str" of "Union[str, - # IO[Any], IOBase]" has no attribute "read" [union-attr] - - # pandas\io\sas\sas7bdat.py:252: error: Item "IOBase" of "Union[str, - # IO[Any], IOBase]" has no attribute "read" [union-attr] - buf = self._path_or_buf.read( # type: ignore[union-attr] - self.header_length - 288 - ) + buf = self._path_or_buf.read(self.header_length - 288) self._cached_page += buf if len(self._cached_page) != self.header_length: self.close() @@ -383,16 +367,8 @@ def _read_int(self, offset: int, width: int) -> int: def _read_bytes(self, offset: int, length: int): if self._cached_page is None: - # pandas\io\sas\sas7bdat.py:333: error: Item "str" of "Union[str, - # IO[Any], IOBase]" has no attribute "seek" [union-attr] - self._path_or_buf.seek(offset) # type: ignore[union-attr] - # pandas\io\sas\sas7bdat.py:334: error: Item "str" of "Union[str, - # IO[Any], IOBase]" has no attribute "read" [union-attr] - - # pandas\io\sas\sas7bdat.py:334: error: Item "IOBase" of - # "Union[str, IO[Any], IOBase]" has no attribute "read" - # [union-attr] - buf = self._path_or_buf.read(length) # type: ignore[union-attr] + self._path_or_buf.seek(offset) + buf = self._path_or_buf.read(length) if len(buf) < length: self.close() msg = f"Unable to read {length:d} bytes from file position {offset:d}." @@ -407,15 +383,7 @@ def _read_bytes(self, offset: int, length: int): def _parse_metadata(self): done = False while not done: - # pandas\io\sas\sas7bdat.py:349: error: Item "str" of "Union[str, - # IO[Any], IOBase]" has no attribute "read" [union-attr] - - # pandas\io\sas\sas7bdat.py:349: error: Item "IOBase" of - # "Union[str, IO[Any], IOBase]" has no attribute "read" - # [union-attr] - self._cached_page = self._path_or_buf.read( # type: ignore[union-attr] - self._page_length - ) + self._cached_page = self._path_or_buf.read(self._page_length) if len(self._cached_page) <= 0: break if len(self._cached_page) != self._page_length: @@ -589,10 +557,7 @@ def _process_columntext_subheader(self, offset, length): compression_literal = b"" for cl in const.compression_literals: if cl in cname_raw: - # pandas\io\sas\sas7bdat.py:525: error: Incompatible types - # in assignment (expression has type "bytes", variable has - # type "str") [assignment] - compression_literal = cl # type: ignore[assignment] + compression_literal = cl self.compression = compression_literal offset -= self._int_length @@ -609,13 +574,7 @@ def _process_columntext_subheader(self, offset, length): offset1 += 4 buf = self._read_bytes(offset1, self._lcp) self.creator_proc = buf[0 : self._lcp] - # pandas\io\sas\sas7bdat.py:542: error: Non-overlapping equality - # check (left operand type: "str", right operand type: "bytes") - # [comparison-overlap] - elif ( - compression_literal # type: ignore[comparison-overlap] - == const.rle_compression - ): + elif compression_literal == const.rle_compression: offset1 = offset + 40 if self.U64: offset1 += 4 @@ -781,14 +740,7 @@ def read(self, nrows=None): def _read_next_page(self): self._current_page_data_subheader_pointers = [] - # pandas\io\sas\sas7bdat.py:707: error: Item "str" of "Union[str, - # IO[Any], IOBase]" has no attribute "read" [union-attr] - - # pandas\io\sas\sas7bdat.py:707: error: Item "IOBase" of "Union[str, - # IO[Any], IOBase]" has no attribute "read" [union-attr] - self._cached_page = self._path_or_buf.read( # type: ignore[union-attr] - self._page_length - ) + self._cached_page = self._path_or_buf.read(self._page_length) if len(self._cached_page) <= 0: return True elif len(self._cached_page) != self._page_length: diff --git a/pandas/io/sas/sas_xport.py b/pandas/io/sas/sas_xport.py index 731114d041f4f..2a48abe9fbd63 100644 --- a/pandas/io/sas/sas_xport.py +++ b/pandas/io/sas/sas_xport.py @@ -356,20 +356,13 @@ def _read_header(self): msg = f"Floating field width {fl} is not between 2 and 8." raise TypeError(msg) - # pandas\io\sas\sas_xport.py:359: error: "bytes" has no attribute - # "items" [attr-defined] - for k, v in field.items(): # type: ignore[attr-defined] + for k, v in field.items(): try: - # pandas\io\sas\sas_xport.py:361: error: Unsupported target - # for indexed assignment ("bytes") [index] - field[k] = v.strip() # type: ignore[index] + field[k] = v.strip() except AttributeError: pass - # pandas\io\sas\sas_xport.py:365: error: No overload variant of - # "__getitem__" of "bytes" matches argument type "str" - # [call-overload] - obs_length += field["field_length"] # type: ignore[call-overload] + obs_length += field["field_length"] fields += [field] header = self._get_row() @@ -382,21 +375,11 @@ def _read_header(self): self.record_start = self.filepath_or_buffer.tell() self.nobs = self._record_count() - # pandas\io\sas\sas_xport.py:378: error: No overload variant of - # "__getitem__" of "bytes" matches argument type "str" [call-overload] - self.columns = [ - x["name"].decode() for x in self.fields # type: ignore[call-overload] - ] + self.columns = [x["name"].decode() for x in self.fields] # Setup the dtype. dtypel = [ - # pandas\io\sas\sas_xport.py:382: error: No overload variant of - # "__getitem__" of "bytes" matches argument type "str" - # [call-overload] - ( - "s" + str(i), - "S" + str(field["field_length"]), # type: ignore[call-overload] - ) + ("s" + str(i), "S" + str(field["field_length"])) for i, field in enumerate(self.fields) ] dtype = np.dtype(dtypel) @@ -429,13 +412,7 @@ def _record_count(self) -> int: last_card = np.frombuffer(last_card_bytes, dtype=np.uint64) # 8 byte blank - - # pandas\io\sas\sas_xport.py:415: error: Non-overlapping equality check - # (left operand type: "bytes", right operand type: - # "Literal[2314885530818453536]") [comparison-overlap] - ix = np.flatnonzero( - last_card == 2314885530818453536 # type: ignore[comparison-overlap] - ) + ix = np.flatnonzero(last_card == 2314885530818453536) if len(ix) == 0: tail_pad = 0 @@ -491,24 +468,13 @@ def read(self, nrows=None): df = pd.DataFrame(index=range(read_lines)) for j, x in enumerate(self.columns): vec = data["s" + str(j)] - # pandas\io\sas\sas_xport.py:471: error: No overload variant of - # "__getitem__" of "bytes" matches argument type "str" - # [call-overload] - ntype = self.fields[j]["ntype"] # type: ignore[call-overload] + ntype = self.fields[j]["ntype"] if ntype == "numeric": - # pandas\io\sas\sas_xport.py:473: error: No overload variant of - # "__getitem__" of "bytes" matches argument type "str" - # [call-overload] - vec = _handle_truncated_float_vec( - vec, self.fields[j]["field_length"] # type: ignore[call-overload] - ) + vec = _handle_truncated_float_vec(vec, self.fields[j]["field_length"]) miss = self._missing_double(vec) v = _parse_float_vec(vec) v[miss] = np.nan - # pandas\io\sas\sas_xport.py:477: error: No overload variant of - # "__getitem__" of "bytes" matches argument type "str" - # [call-overload] - elif self.fields[j]["ntype"] == "char": # type: ignore[call-overload] + elif self.fields[j]["ntype"] == "char": v = [y.rstrip() for y in vec] if self._encoding is not None: From f0d6dea455090a828ea340e00a57521aeaf18c7c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 12 Oct 2020 17:37:49 +0100 Subject: [PATCH 36/45] remove unused 'type: ignore' comments --- pandas/core/generic.py | 24 ++++++++++++++---------- pandas/core/internals/blocks.py | 17 +++++++---------- pandas/core/internals/construction.py | 5 +---- pandas/core/internals/ops.py | 12 +++--------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 71d2df8e57986..08b80509d4804 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11133,34 +11133,38 @@ def _inplace_method(self, other, op): return self def __iadd__(self, other): - return self._inplace_method(other, type(self).__add__) + return self._inplace_method(other, type(self).__add__) # type: ignore[operator] def __isub__(self, other): - return self._inplace_method(other, type(self).__sub__) + return self._inplace_method(other, type(self).__sub__) # type: ignore[operator] def __imul__(self, other): - return self._inplace_method(other, type(self).__mul__) + return self._inplace_method(other, type(self).__mul__) # type: ignore[operator] def __itruediv__(self, other): - return self._inplace_method(other, type(self).__truediv__) + return self._inplace_method( + other, type(self).__truediv__ # type: ignore[operator] + ) def __ifloordiv__(self, other): - return self._inplace_method(other, type(self).__floordiv__) + return self._inplace_method( + other, type(self).__floordiv__ # type: ignore[operator] + ) def __imod__(self, other): - return self._inplace_method(other, type(self).__mod__) + return self._inplace_method(other, type(self).__mod__) # type: ignore[operator] def __ipow__(self, other): - return self._inplace_method(other, type(self).__pow__) + return self._inplace_method(other, type(self).__pow__) # type: ignore[operator] def __iand__(self, other): - return self._inplace_method(other, type(self).__and__) + return self._inplace_method(other, type(self).__and__) # type: ignore[operator] def __ior__(self, other): - return self._inplace_method(other, type(self).__or__) + return self._inplace_method(other, type(self).__or__) # type: ignore[operator] def __ixor__(self, other): - return self._inplace_method(other, type(self).__xor__) + return self._inplace_method(other, type(self).__xor__) # type: ignore[operator] # ---------------------------------------------------------------------- # Misc methods diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index cbf5c15433a05..98ae52b04cee3 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2686,7 +2686,7 @@ def get_block_type(values, dtype=None): cls = CategoricalBlock elif issubclass(vtype, np.datetime64): assert not is_datetime64tz_dtype(values.dtype) - cls = DatetimeBlock # type: ignore[assignment] + cls = DatetimeBlock elif is_datetime64tz_dtype(values.dtype): cls = DatetimeTZBlock elif is_interval_dtype(dtype) or is_period_dtype(dtype): @@ -2694,21 +2694,18 @@ def get_block_type(values, dtype=None): elif is_extension_array_dtype(values.dtype): cls = ExtensionBlock elif issubclass(vtype, np.floating): - cls = FloatBlock # type: ignore[assignment] + cls = FloatBlock elif issubclass(vtype, np.timedelta64): assert issubclass(vtype, np.integer) - cls = TimeDeltaBlock # type: ignore[assignment] + cls = TimeDeltaBlock elif issubclass(vtype, np.complexfloating): - cls = ComplexBlock # type: ignore[assignment] + cls = ComplexBlock elif issubclass(vtype, np.integer): - cls = IntBlock # type: ignore[assignment] + cls = IntBlock elif dtype == np.bool_: - cls = BoolBlock # type: ignore[assignment] + cls = BoolBlock else: - # pandas\core\internals\blocks.py:2766: error: Incompatible types in - # assignment (expression has type "Type[ObjectBlock]", variable has - # type "Type[ExtensionBlock]") [assignment] - cls = ObjectBlock # type: ignore[assignment] + cls = ObjectBlock return cls diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 50c8598a4c349..bb8283604abb0 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -443,10 +443,7 @@ def get_names_from_index(data): if n is not None: index[i] = n else: - # pandas\core\internals\construction.py:446: error: No overload - # variant of "__setitem__" of "list" matches argument types "int", - # "str" [call-overload] - index[i] = f"Unnamed {count}" # type: ignore[call-overload] + index[i] = f"Unnamed {count}" count += 1 return index diff --git a/pandas/core/internals/ops.py b/pandas/core/internals/ops.py index 89124d24a76c7..d7ea5d613d96a 100644 --- a/pandas/core/internals/ops.py +++ b/pandas/core/internals/ops.py @@ -23,9 +23,7 @@ def _iter_block_pairs( for n, blk in enumerate(left.blocks): locs = blk.mgr_locs - # pandas\core\internals\ops.py:26: error: Cannot determine type of - # 'values' [has-type] - blk_vals = blk.values # type: ignore[has-type] + blk_vals = blk.values left_ea = not isinstance(blk_vals, np.ndarray) @@ -97,12 +95,8 @@ def _get_same_shape_values( """ Slice lblk.values to align with rblk. Squeeze if we have EAs. """ - # pandas\core\internals\ops.py:98: error: Cannot determine type of 'values' - # [has-type] - lvals = lblk.values # type: ignore[has-type] - # pandas\core\internals\ops.py:99: error: Cannot determine type of 'values' - # [has-type] - rvals = rblk.values # type: ignore[has-type] + lvals = lblk.values + rvals = rblk.values # Require that the indexing into lvals be slice-like assert rblk.mgr_locs.is_slice_like, rblk.mgr_locs From ec109393c9ce235be79600bd67b5c4fd30db0d11 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 12 Oct 2020 19:48:20 +0100 Subject: [PATCH 37/45] black fixup --- pandas/core/indexes/base.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 8f2557318e94c..b3f5fb6f0291a 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3756,9 +3756,7 @@ def _get_leaf_sorter(labels): left_indexer = None join_index = left else: # sort the leaves - left_indexer = _get_leaf_sorter( - left.codes[: level + 1] - ) + left_indexer = _get_leaf_sorter(left.codes[: level + 1]) join_index = left[left_indexer] else: @@ -3766,9 +3764,7 @@ def _get_leaf_sorter(labels): rev_indexer = lib.get_reverse_indexer(left_lev_indexer, len(old_level)) new_lev_codes = algos.take_nd( - rev_indexer, - left.codes[level], - allow_fill=False + rev_indexer, left.codes[level], allow_fill=False ) new_codes = list(left.codes) From fe92e38f71e4c45a28ebb1ef8ee194be1bce5b60 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 15 Oct 2020 19:26:10 +0100 Subject: [PATCH 38/45] remove unused 'type: ignore' comments --- pandas/core/base.py | 36 +++++--------- pandas/core/frame.py | 7 ++- pandas/core/indexes/category.py | 18 ++----- pandas/io/pytables.py | 43 ++++------------- pandas/plotting/_matplotlib/core.py | 74 +++++++---------------------- 5 files changed, 46 insertions(+), 132 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 1f95e0cb8dc1a..6388d52d30e0c 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -593,9 +593,7 @@ def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default, **kwargs): array(['1999-12-31T23:00:00.000000000', '2000-01-01T23:00:00...'], dtype='datetime64[ns]') """ - # pandas\core\base.py:836: error: "IndexOpsMixin" has no attribute - # "dtype" [attr-defined] - if is_extension_array_dtype(self.dtype): # type: ignore[attr-defined] + if is_extension_array_dtype(self.dtype): # pandas\core\base.py:837: error: Too many arguments for "to_numpy" # of "ExtensionArray" [call-arg] return self.array.to_numpy( # type: ignore[call-arg] @@ -889,13 +887,18 @@ def _map_values(self, mapper, na_action=None): # Since values were input this means we came from either # a dict or a series and mapper should be an index - # pandas\core\base.py:1122: error: "IndexOpsMixin" has no attribute - # "dtype" [attr-defined] - if is_categorical_dtype(self.dtype): # type: ignore[attr-defined] + if is_categorical_dtype(self.dtype): # use the built in categorical series mapper which saves # time by mapping the categories instead of all values - self = cast("Categorical", self) - return self._values.map(mapper) + + # pandas\core\base.py:893: error: Incompatible types in + # assignment (expression has type "Categorical", variable has + # type "IndexOpsMixin") [assignment] + self = cast("Categorical", self) # type: ignore[assignment] + # pandas\core\base.py:894: error: Item "ExtensionArray" of + # "Union[ExtensionArray, Any]" has no attribute "map" + # [union-attr] + return self._values.map(mapper) # type: ignore[union-attr] values = self._values @@ -906,11 +909,7 @@ def _map_values(self, mapper, na_action=None): # we must convert to python types - # pandas\core\base.py:1135: error: "IndexOpsMixin" has no attribute - # "dtype" [attr-defined] - if is_extension_array_dtype( - self.dtype # type: ignore[attr-defined] - ) and hasattr(self._values, "map"): + if is_extension_array_dtype(self.dtype) and hasattr(self._values, "map"): # GH#23179 some EAs do not have `map` values = self._values if na_action is not None: @@ -1040,16 +1039,7 @@ def unique(self): if not isinstance(values, np.ndarray): result = values.unique() - # pandas\core\base.py:1258: error: "IndexOpsMixin" has no attribute - # "dtype" [attr-defined] - if ( - self.dtype.kind # type: ignore[attr-defined] - in [ - "m", - "M", - ] - and isinstance(self, ABCSeries) - ): + if self.dtype.kind in ["m", "M"] and isinstance(self, ABCSeries): # GH#31182 Series._values returns EA, unpack for backward-compat if getattr(self.dtype, "tz", None) is None: result = np.asarray(result) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 539275c7ff617..6a43f88168319 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3824,7 +3824,12 @@ def reindexer(value): value, len(self.index), infer_dtype ) else: - value = cast_scalar_to_array(len(self.index), value) + # pandas\core\frame.py:3827: error: Argument 1 to + # "cast_scalar_to_array" has incompatible type "int"; expected + # "Tuple[Any, ...]" [arg-type] + value = cast_scalar_to_array( + len(self.index), value # type: ignore[arg-type] + ) value = maybe_cast_to_datetime(value, infer_dtype) diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index dd49b8a3186d9..f1a2864bdadbd 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -547,12 +547,7 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None): "method='nearest' not implemented yet for CategoricalIndex" ) - # pandas\core\indexes\category.py:547: error: Item "ExtensionArray" of - # "Union[ExtensionArray, Any]" has no attribute "_validate_listlike" - # [union-attr] - codes = self._values._validate_listlike( # type: ignore[union-attr] - target._values - ) + codes = self._values._validate_listlike(target._values) indexer, _ = self._engine.get_indexer_non_unique(codes) return ensure_platform_int(indexer) @@ -560,12 +555,7 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None): def get_indexer_non_unique(self, target): target = ibase.ensure_index(target) - # pandas\core\indexes\category.py:555: error: Item "ExtensionArray" of - # "Union[ExtensionArray, Any]" has no attribute "_validate_listlike" - # [union-attr] - codes = self._values._validate_listlike( # type: ignore[union-attr] - target._values - ) + codes = self._values._validate_listlike(target._values) indexer, missing = self._engine.get_indexer_non_unique(codes) return ensure_platform_int(indexer), missing @@ -671,9 +661,7 @@ def map(self, mapper): >>> idx.map({'a': 'first', 'b': 'second'}) Index(['first', 'second', nan], dtype='object') """ - # pandas\core\indexes\category.py:661: error: Item "ExtensionArray" of - # "Union[ExtensionArray, Any]" has no attribute "map" [union-attr] - mapped = self._values.map(mapper) # type: ignore[union-attr] + mapped = self._values.map(mapper) return Index(mapped, name=self.name) def delete(self, loc): diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index d2c2ce13c18a3..ffc3a4501470f 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1398,24 +1398,13 @@ def groups(self): assert _table_mod is not None # for mypy return [ g - # pandas\io\pytables.py:1398: error: Item "None" of "Optional[Any]" - # has no attribute "walk_groups" [union-attr] - for g in self._handle.walk_groups() # type: ignore[union-attr] + for g in self._handle.walk_groups() if ( - # pandas\io\pytables.py:1400: error: Item "None" of - # "Optional[Any]" has no attribute "link" [union-attr] - not isinstance(g, _table_mod.link.Link) # type: ignore[union-attr] + not isinstance(g, _table_mod.link.Link) and ( getattr(g._v_attrs, "pandas_type", None) or getattr(g, "table", None) - # pandas\io\pytables.py:1404: error: Item "None" of - # "Optional[Any]" has no attribute "table" [union-attr] - or ( - isinstance( - g, _table_mod.table.Table # type: ignore[union-attr] - ) - and g._v_name != "table" - ) + or (isinstance(g, _table_mod.table.Table) and g._v_name != "table") ) ) ] @@ -1463,11 +1452,7 @@ def walk(self, where="/"): for child in g._v_children.values(): pandas_type = getattr(child._v_attrs, "pandas_type", None) if pandas_type is None: - # pandas\io\pytables.py:1449: error: Item "None" of - # "Optional[Any]" has no attribute "group" [union-attr] - if isinstance( - child, _table_mod.group.Group # type: ignore[union-attr] - ): + if isinstance(child, _table_mod.group.Group): groups.append(child._v_name) else: leaves.append(child._v_name) @@ -1887,11 +1872,7 @@ def __iter__(self): raise ValueError("Cannot iterate until get_result is called.") while current < self.stop: stop = min(current + self.chunksize, self.stop) - # pandas\io\pytables.py:1867: error: Value of type "None" is not - # indexable [index] - value = self.func( - None, None, self.coordinates[current:stop] # type: ignore[index] - ) + value = self.func(None, None, self.coordinates[current:stop]) current = stop if value is None or not len(value): continue @@ -4622,10 +4603,7 @@ def get_attrs(self): """ retrieve our attributes """ self.non_index_axes = [] self.nan_rep = None - # pandas\io\pytables.py:4592: error: Incompatible types in assignment - # (expression has type "List[]", variable has type "int") - # [assignment] - self.levels = [] # type: ignore[assignment] + self.levels = [] self.index_axes = [a for a in self.indexables if a.is_an_indexable] self.values_axes = [a for a in self.indexables if not a.is_an_indexable] @@ -4662,10 +4640,7 @@ def indexables(self): meta=meta, metadata=md, ) - # pandas\io\pytables.py:4629: error: Argument 1 to "append" of - # "list" has incompatible type "GenericDataIndexableCol"; expected - # "GenericIndexCol" [arg-type] - _indexables.append(dc) # type: ignore[arg-type] + _indexables.append(dc) return _indexables @@ -5215,9 +5190,7 @@ def select_coords(self): start += nrows if stop is None: stop = nrows - # pandas\io\pytables.py:5173: error: Unsupported operand types for > - # ("int" and "None") [operator] - elif stop < 0: # type: ignore[operator] + elif stop < 0: stop += nrows if self.condition is not None: diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index b80a6a9c0a039..2501d84de4459 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -279,9 +279,7 @@ def generate(self): self._make_legend() self._adorn_subplots() - # pandas\plotting\_matplotlib\core.py:280: error: "None" has no - # attribute "__iter__" (not iterable) [attr-defined] - for ax in self.axes: # type: ignore[attr-defined] + for ax in self.axes: self._post_plot_logic_common(ax, self.data) self._post_plot_logic(ax, self.data) @@ -371,9 +369,7 @@ def result(self): """ if self.subplots: if self.layout is not None and not is_list_like(self.ax): - # pandas\plotting\_matplotlib\core.py:370: error: "None" has no - # attribute "reshape" [attr-defined] - return self.axes.reshape(*self.layout) # type: ignore[attr-defined] + return self.axes.reshape(*self.layout) else: return self.axes else: @@ -383,16 +379,9 @@ def result(self): ) if sec_true or all_sec: # if all data is plotted on secondary, return right axes - - # pandas\plotting\_matplotlib\core.py:380: error: Value of type - # "None" is not indexable [index] - return self._get_ax_layer( - self.axes[0], primary=False # type: ignore[index] - ) + return self._get_ax_layer(self.axes[0], primary=False) else: - # pandas\plotting\_matplotlib\core.py:382: error: Value of type - # "None" is not indexable [index] - return self.axes[0] # type: ignore[index] + return self.axes[0] def _compute_plot_data(self): data = self.data @@ -479,9 +468,7 @@ def _post_plot_logic(self, ax, data): def _adorn_subplots(self): """Common post process unrelated to data""" - # pandas\plotting\_matplotlib\core.py:469: error: Argument 1 to "len" - # has incompatible type "None"; expected "Sized" [arg-type] - if len(self.axes) > 0: # type: ignore[arg-type] + if len(self.axes) > 0: all_axes = self._get_subplots() nrows, ncols = self._get_axes_layout() handle_shared_axes( @@ -494,9 +481,7 @@ def _adorn_subplots(self): sharey=self.sharey, ) - # pandas\plotting\_matplotlib\core.py:482: error: "None" has no - # attribute "__iter__" (not iterable) [attr-defined] - for ax in self.axes: # type: ignore[attr-defined] + for ax in self.axes: if self.yticks is not None: ax.set_yticks(self.yticks) @@ -528,12 +513,7 @@ def _adorn_subplots(self): f"number of columns = {self.nseries}" ) - # pandas\plotting\_matplotlib\core.py:514: error: No - # overload variant of "zip" matches argument types "None", - # "Any" [call-overload] - for (ax, title) in zip( - self.axes, self.title # type: ignore[call-overload] - ): + for (ax, title) in zip(self.axes, self.title): ax.set_title(title) else: self.fig.suptitle(self.title) @@ -544,9 +524,7 @@ def _adorn_subplots(self): "unless `subplots=True` is passed" ) raise ValueError(msg) - # pandas\plotting\_matplotlib\core.py:525: error: Value of type - # "None" is not indexable [index] - self.axes[0].set_title(self.title) # type: ignore[index] + self.axes[0].set_title(self.title) def _apply_axis_properties(self, axis: "Axis", rot=None, fontsize=None): """ @@ -584,11 +562,7 @@ def _add_legend_handle(self, handle, label, index=None): self.legend_labels.append(label) def _make_legend(self): - # pandas\plotting\_matplotlib\core.py:563: error: Value of type "None" - # is not indexable [index] - ax, leg, handle = self._get_ax_legend_handle( - self.axes[0] # type: ignore[index] - ) + ax, leg, handle = self._get_ax_legend_handle(self.axes[0]) handles = [] labels = [] @@ -628,9 +602,7 @@ def _make_legend(self): ax.legend(handles, labels, loc="best", title=title) elif self.subplots and self.legend: - # pandas\plotting\_matplotlib\core.py:591: error: "None" has no - # attribute "__iter__" (not iterable) [attr-defined] - for ax in self.axes: # type: ignore[attr-defined] + for ax in self.axes: if ax.get_visible(): ax.legend(loc="best") @@ -742,17 +714,11 @@ def _get_ax_layer(cls, ax, primary=True): def _get_ax(self, i: int): # get the twinx ax if appropriate if self.subplots: - # pandas\plotting\_matplotlib\core.py:703: error: Value of type - # "None" is not indexable [index] - ax = self.axes[i] # type: ignore[index] + ax = self.axes[i] ax = self._maybe_right_yaxis(ax, i) - # pandas\plotting\_matplotlib\core.py:705: error: Unsupported - # target for indexed assignment ("None") [index] - self.axes[i] = ax # type: ignore[index] + self.axes[i] = ax else: - # pandas\plotting\_matplotlib\core.py:707: error: Value of type - # "None" is not indexable [index] - ax = self.axes[0] # type: ignore[index] + ax = self.axes[0] ax = self._maybe_right_yaxis(ax, i) ax.get_yaxis().set_visible(True) @@ -923,11 +889,7 @@ def _get_subplots(self): from matplotlib.axes import Subplot return [ - # pandas\plotting\_matplotlib\core.py:878: error: Value of type - # "None" is not indexable [index] - ax - for ax in self.axes[0].get_figure().get_axes() # type: ignore[index] - if isinstance(ax, Subplot) + ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot) ] def _get_axes_layout(self) -> Tuple[int, int]: @@ -1036,9 +998,7 @@ def __init__(self, data, x, y, s=None, c=None, **kwargs): def _make_plot(self): x, y, c, data = self.x, self.y, self.c, self.data - # pandas\plotting\_matplotlib\core.py:985: error: Value of type "None" - # is not indexable [index] - ax = self.axes[0] # type: ignore[index] + ax = self.axes[0] c_is_column = is_hashable(c) and c in self.data.columns @@ -1103,9 +1063,7 @@ def __init__(self, data, x, y, C=None, **kwargs): def _make_plot(self): x, y, data, C = self.x, self.y, self.data, self.C - # pandas\plotting\_matplotlib\core.py:1050: error: Value of type "None" - # is not indexable [index] - ax = self.axes[0] # type: ignore[index] + ax = self.axes[0] # pandas uses colormap, matplotlib uses cmap. cmap = self.colormap or "BuGn" cmap = self.plt.cm.get_cmap(cmap) From d1f19da92bc136d08077f271390782cbf76e0b59 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 17 Oct 2020 12:18:30 +0100 Subject: [PATCH 39/45] remove unused 'type: ignore' comment --- pandas/core/window/rolling.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index ab7602bfe7a01..1fcc47931e882 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1386,9 +1386,7 @@ def _generate_cython_apply_func( ) -> Callable[[np.ndarray, np.ndarray, np.ndarray, int], np.ndarray]: from pandas import Series - # pandas\core\window\rolling.py:1369: error: "partial" gets multiple - # values for keyword argument "func" [misc] - window_func = partial( # type: ignore[misc] + window_func = partial( self._get_roll_func("roll_apply"), args=args, kwargs=kwargs, From 6b5ef52db2f72942338c6980b9580a3216bcaa68 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 24 Oct 2020 11:23:27 +0100 Subject: [PATCH 40/45] remove unused 'type: ignore' comment --- pandas/core/arrays/datetimelike.py | 4 +++- pandas/core/indexes/category.py | 10 +--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 48b09db520432..712c5d88b4f74 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -429,7 +429,9 @@ def _validate_comparison_value(self, other): raise InvalidComparison(other) if isinstance(other, self._recognized_scalars) or other is NaT: - other = self._scalar_type(other) + # pandas\core\arrays\datetimelike.py:432: error: Too many arguments + # for "object" [call-arg] + other = self._scalar_type(other) # type: ignore[call-arg] try: self._check_compatible_with(other) except TypeError as err: diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index 1b4d189328672..d391af3ccca88 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -703,15 +703,7 @@ def insert(self, loc: int, item): def _concat(self, to_concat, name): # if calling index is category, don't check dtype of others - - # pandas\core\indexes\category.py:704: error: "bool" has no attribute - # "codes" [attr-defined] - codes = np.concatenate( - [ - self._is_dtype_compat(c).codes # type: ignore[attr-defined] - for c in to_concat - ] - ) + codes = np.concatenate([self._is_dtype_compat(c).codes for c in to_concat]) cat = self._data._from_backing_data(codes) return type(self)._simple_new(cat, name=name) From 4ca8e451359e6aa73ff3e6f62737abb0f5ef5376 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 31 Oct 2020 12:59:12 +0000 Subject: [PATCH 41/45] remove unused 'type: ignore' comments --- pandas/core/reshape/concat.py | 18 ++---------------- pandas/plotting/_matplotlib/converter.py | 12 +++--------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index b59245e184593..8a59b576b8234 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -470,15 +470,7 @@ def get_result(self): arrs = [ser._values for ser in self.objs] res = concat_compat(arrs, axis=0) - # pandas\core\reshape\concat.py:470: error: Unexpected keyword - # argument "index" for "NDFrame" [call-arg] - - # pandas\core\reshape\concat.py:470: error: Unexpected keyword - # argument "name" for "NDFrame" [call-arg] - - # pandas\core\reshape\concat.py:470: error: Unexpected keyword - # argument "dtype" for "NDFrame" [call-arg] - result = cons( # type: ignore[call-arg] + result = cons( res, index=self.new_axes[0], name=name, dtype=res.dtype ) return result.__finalize__(self, method="concat") @@ -491,13 +483,7 @@ def get_result(self): cons = sample._constructor_expanddim index, columns = self.new_axes - # pandas\core\reshape\concat.py:481: error: Argument 1 to - # "NDFrame" has incompatible type "Dict[int, FrameOrSeries]"; - # expected "BlockManager" [arg-type] - - # pandas\core\reshape\concat.py:484: error: Unexpected keyword - # argument "index" for "NDFrame" [call-arg] - df = cons(data, index=index) # type: ignore[arg-type, call-arg] + df = cons(data, index=index) df.columns = columns return df.__finalize__(self, method="concat") diff --git a/pandas/plotting/_matplotlib/converter.py b/pandas/plotting/_matplotlib/converter.py index ce7d69dea6c4f..27c7b931b7136 100644 --- a/pandas/plotting/_matplotlib/converter.py +++ b/pandas/plotting/_matplotlib/converter.py @@ -573,9 +573,7 @@ def first_label(label_flags): month_start = period_break(dates_, "month") def _hour_finder(label_interval, force_year_start): - # pandas\plotting\_matplotlib\converter.py:576: error: - # "PeriodIndex" has no attribute "hour" [attr-defined] - _hour = dates_.hour # type: ignore[attr-defined] + _hour = dates_.hour _prev_hour = (dates_ - 1 * dates_.freq).hour hour_start = (_hour - _prev_hour) != 0 info_maj[day_start] = True @@ -589,9 +587,7 @@ def _hour_finder(label_interval, force_year_start): def _minute_finder(label_interval): hour_start = period_break(dates_, "hour") - # pandas\plotting\_matplotlib\converter.py:590: error: - # "PeriodIndex" has no attribute "minute" [attr-defined] - _minute = dates_.minute # type: ignore[attr-defined] + _minute = dates_.minute _prev_minute = (dates_ - 1 * dates_.freq).minute minute_start = (_minute - _prev_minute) != 0 info_maj[hour_start] = True @@ -604,9 +600,7 @@ def _minute_finder(label_interval): def _second_finder(label_interval): minute_start = period_break(dates_, "minute") - # pandas\plotting\_matplotlib\converter.py:603: error: - # "PeriodIndex" has no attribute "second" [attr-defined] - _second = dates_.second # type: ignore[attr-defined] + _second = dates_.second _prev_second = (dates_ - 1 * dates_.freq).second second_start = (_second - _prev_second) != 0 info["maj"][minute_start] = True From 58142c3f55f9f4a8152acef67e54967fbaf89741 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 31 Oct 2020 13:21:38 +0000 Subject: [PATCH 42/45] tidy diff --- pandas/core/arrays/datetimelike.py | 4 +--- pandas/core/base.py | 2 -- pandas/core/generic.py | 17 +++++++++++++++++ pandas/core/reshape/concat.py | 4 +--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 2ca0932f90402..81cdec0e99ff7 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -680,8 +680,7 @@ def value_counts(self, dropna=False): result = value_counts(values, sort=False, dropna=dropna) index = Index( - cls(result.index.view("i8"), dtype=self.dtype), - name=result.index.name, + cls(result.index.view("i8"), dtype=self.dtype), name=result.index.name ) return Series(result._values, index=index, name=result.name) @@ -939,7 +938,6 @@ def _add_timedeltalike_scalar(self, other): # i.e np.timedelta64("NaT"), not recognized by delta_to_nanoseconds new_values = np.empty(self.shape, dtype="i8") new_values[:] = iNaT - return type(self)(new_values, dtype=self.dtype) inc = delta_to_nanoseconds(other) diff --git a/pandas/core/base.py b/pandas/core/base.py index b2d034bc3ab4a..5b59a03e55a6a 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -886,7 +886,6 @@ def _map_values(self, mapper, na_action=None): if isinstance(mapper, ABCSeries): # Since values were input this means we came from either # a dict or a series and mapper should be an index - if is_categorical_dtype(self.dtype): # use the built in categorical series mapper which saves # time by mapping the categories instead of all values @@ -908,7 +907,6 @@ def _map_values(self, mapper, na_action=None): return new_values # we must convert to python types - if is_extension_array_dtype(self.dtype) and hasattr(self._values, "map"): # GH#23179 some EAs do not have `map` values = self._values diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b653ab79ddbb6..767b4029cf43b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10720,6 +10720,23 @@ def _add_numeric_operations(cls): empty_value=False, ) def any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): + return NDFrame.any(self, axis, bool_only, skipna, level, **kwargs) + + # pandas\core\generic.py:10725: error: Cannot assign to a method + # [assignment] + cls.any = any # type: ignore[assignment] + + @doc( + _bool_doc, + desc=_all_desc, + name1=name1, + name2=name2, + axis_descr=axis_descr, + see_also=_all_see_also, + examples=_all_examples, + empty_value=True, + ) + def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): return NDFrame.all(self, axis, bool_only, skipna, level, **kwargs) # pandas\core\generic.py:10719: error: Cannot assign to a method diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 8a59b576b8234..77b1076920f20 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -470,9 +470,7 @@ def get_result(self): arrs = [ser._values for ser in self.objs] res = concat_compat(arrs, axis=0) - result = cons( - res, index=self.new_axes[0], name=name, dtype=res.dtype - ) + result = cons(res, index=self.new_axes[0], name=name, dtype=res.dtype) return result.__finalize__(self, method="concat") # combine as columns in a frame From f986ac3b49c3ab4f347c893a69ba4efa4fa2b93f Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 1 Nov 2020 12:41:02 +0000 Subject: [PATCH 43/45] fixup for ci --- pandas/_testing.py | 3 +-- pandas/core/groupby/grouper.py | 2 +- pandas/core/indexes/extension.py | 9 ++++++++- setup.cfg | 9 +++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pandas/_testing.py b/pandas/_testing.py index d6c9352a9a405..be43d70806f2e 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -2909,8 +2909,7 @@ def setTZ(tz): pass else: os.environ["TZ"] = tz - # pandas\_testing.py:2845: error: Module has no attribute "tzset" - time.tzset() # type: ignore[attr-defined] + time.tzset() orig_tz = os.environ.get("TZ") setTZ(tz) diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 76ffb3b1aaa40..4e8d01c08e835 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -350,7 +350,7 @@ def _set_grouper(self, obj: FrameOrSeries, sort: bool = False): ): # pandas\core\groupby\grouper.py:348: error: Item "None" of # "Optional[Any]" has no attribute "take" [union-attr] - ax = self._grouper.take(obj.index) # type: ignore + ax = self._grouper.take(obj.index) # type: ignore[union-attr] else: if key not in obj._info_axis: raise KeyError(f"The grouper name {key} is not found") diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index 66f453b5e0125..6df4f55352cfe 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -333,7 +333,14 @@ def insert(self, loc: int, item): def putmask(self, mask, value): try: - value = self._data._validate_where_value(value) + # pandas\core\indexes\extension.py:336: error: + # "NDArrayBackedExtensionArray" has no attribute + # "_validate_where_value"; maybe "_validate_insert_value", + # "_validate_setitem_value", or "_validate_shift_value"? + # [attr-defined] + value = self._data._validate_where_value( # type: ignore[attr-defined] + value + ) except (TypeError, ValueError): return self.astype(object).putmask(mask, value) diff --git a/setup.cfg b/setup.cfg index 0f6e09f6902e7..c83a83d599f6c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -114,10 +114,11 @@ skip_glob = env, skip = pandas/__init__.py [mypy] -ignore_missing_imports=True -no_implicit_optional=True -check_untyped_defs=True -strict_equality=True +platform = linux-64 +ignore_missing_imports = True +no_implicit_optional = True +check_untyped_defs = True +strict_equality = True warn_redundant_casts = True warn_unused_ignores = True show_error_codes = True From 055d11aa56e78efc9a4b62b2245779b6caf2abaa Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 1 Nov 2020 13:18:44 +0000 Subject: [PATCH 44/45] remove assignment to tmp --- pandas/core/computation/expr.py | 11 +++++++---- pandas/core/computation/pytables.py | 3 +-- pandas/core/computation/scope.py | 10 ++++++---- pandas/core/indexes/extension.py | 1 - pandas/io/formats/excel.py | 4 ++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index d2d4106931b8e..0f6d0cc16563f 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -662,8 +662,9 @@ def visit_Call(self, node, side=None, **kwargs): if res is None: # pandas\core\computation\expr.py:663: error: "expr" has no # attribute "id" [attr-defined] - tmp = node.func.id # type: ignore[attr-defined] - raise ValueError(f"Invalid function call {tmp}") + raise ValueError( + f"Invalid function call {node.func.id}" # type: ignore[attr-defined] + ) if hasattr(res, "value"): res = res.value @@ -686,8 +687,10 @@ def visit_Call(self, node, side=None, **kwargs): if not isinstance(key, ast.keyword): # pandas\core\computation\expr.py:684: error: "expr" has no # attribute "id" [attr-defined] - tmp = node.func.id # type: ignore[attr-defined] - raise ValueError(f"keyword error in function call '{tmp}'") + raise ValueError( + "keyword error in function call " # type: ignore[attr-defined] + f"'{node.func.id}'" + ) if key.arg: kwargs[key.arg] = self.visit(key.value).value diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index d69e75e9b6c00..dd622ed724e8f 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -365,8 +365,7 @@ def evaluate(self): class JointConditionBinOp(ConditionBinOp): def evaluate(self): - tmp = f"({self.lhs.condition} {self.op} {self.rhs.condition})" - self.condition = tmp + self.condition = f"({self.lhs.condition} {self.op} {self.rhs.condition})" return self diff --git a/pandas/core/computation/scope.py b/pandas/core/computation/scope.py index 18c16d396e68a..98a16e3c06a2f 100644 --- a/pandas/core/computation/scope.py +++ b/pandas/core/computation/scope.py @@ -133,15 +133,17 @@ def __init__( # pandas\core\computation\scope.py:132: error: Incompatible types # in assignment (expression has type "ChainMap[str, Any]", variable # has type "DeepChainMap[str, Any]") [assignment] - tmp = self.scope.new_child((global_dict or frame.f_globals).copy()) - self.scope = tmp # type: ignore[assignment] + self.scope = self.scope.new_child( # type: ignore[assignment] + (global_dict or frame.f_globals).copy() + ) if not isinstance(local_dict, Scope): # pandas\core\computation\scope.py:134: error: Incompatible # types in assignment (expression has type "ChainMap[str, # Any]", variable has type "DeepChainMap[str, Any]") # [assignment] - tmp = self.scope.new_child((local_dict or frame.f_locals).copy()) - self.scope = tmp # type: ignore[assignment] + self.scope = self.scope.new_child( # type: ignore[assignment] + (local_dict or frame.f_locals).copy() + ) finally: del frame diff --git a/pandas/core/indexes/extension.py b/pandas/core/indexes/extension.py index 6df4f55352cfe..59e811957fa78 100644 --- a/pandas/core/indexes/extension.py +++ b/pandas/core/indexes/extension.py @@ -218,7 +218,6 @@ def __getitem__(self, key): if result.ndim == 1: return type(self)(result, name=self.name) # Unpack to ndarray for MPL compat - # pandas\core\indexes\extension.py:220: error: "ExtensionArray" has # no attribute "_data" [attr-defined] result = result._data # type: ignore[attr-defined] diff --git a/pandas/io/formats/excel.py b/pandas/io/formats/excel.py index b7d4e5e1d753b..57fdc4e146b5c 100644 --- a/pandas/io/formats/excel.py +++ b/pandas/io/formats/excel.py @@ -598,9 +598,9 @@ def _format_header_regular(self): # "len" has incompatible type # "Union[Sequence[Optional[Hashable]], bool]"; expected # "Sized" [arg-type] - tmp = len(self.header) # type: ignore[arg-type] raise ValueError( - f"Writing {len(self.columns)} cols but got {tmp} aliases" + f"Writing {len(self.columns)} " # type: ignore[arg-type] + f"cols but got {len(self.header)} aliases" ) else: colnames = self.header From 0a1315640c77c0c39deeeabf7d3a64f034c1b585 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 8 Nov 2020 12:41:02 +0000 Subject: [PATCH 45/45] add ignores to pandas\io\parsers.py --- pandas/io/parsers.py | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index d814f4147ad97..5725e2304e1d2 100644 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -1406,7 +1406,9 @@ def _validate_parse_dates_presence(self, columns: List[str]) -> None: ) def close(self): - self.handles.close() + # pandas\io\parsers.py:1409: error: "ParserBase" has no attribute + # "handles" [attr-defined] + self.handles.close() # type: ignore[attr-defined] @property def _has_complex_date_col(self): @@ -1858,7 +1860,30 @@ def __init__(self, src, **kwds): kwds.pop("memory_map", None) kwds.pop("compression", None) if self.handles.is_mmap and hasattr(self.handles.handle, "mmap"): - self.handles.handle = self.handles.handle.mmap + # pandas\io\parsers.py:1861: error: Item "IO[Any]" of + # "Union[IO[Any], RawIOBase, BufferedIOBase, TextIOBase, + # TextIOWrapper, mmap]" has no attribute "mmap" [union-attr] + + # pandas\io\parsers.py:1861: error: Item "RawIOBase" of + # "Union[IO[Any], RawIOBase, BufferedIOBase, TextIOBase, + # TextIOWrapper, mmap]" has no attribute "mmap" [union-attr] + + # pandas\io\parsers.py:1861: error: Item "BufferedIOBase" of + # "Union[IO[Any], RawIOBase, BufferedIOBase, TextIOBase, + # TextIOWrapper, mmap]" has no attribute "mmap" [union-attr] + + # pandas\io\parsers.py:1861: error: Item "TextIOBase" of + # "Union[IO[Any], RawIOBase, BufferedIOBase, TextIOBase, + # TextIOWrapper, mmap]" has no attribute "mmap" [union-attr] + + # pandas\io\parsers.py:1861: error: Item "TextIOWrapper" of + # "Union[IO[Any], RawIOBase, BufferedIOBase, TextIOBase, + # TextIOWrapper, mmap]" has no attribute "mmap" [union-attr] + + # pandas\io\parsers.py:1861: error: Item "mmap" of "Union[IO[Any], + # RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap]" has + # no attribute "mmap" [union-attr] + self.handles.handle = self.handles.handle.mmap # type: ignore[union-attr] # #2442 kwds["allow_leading_cols"] = self.index_col is not False @@ -2424,7 +2449,11 @@ def _read(): reader = _read() - self.data = reader + # pandas\io\parsers.py:2427: error: Incompatible types in assignment + # (expression has type "_reader", variable has type "Union[IO[Any], + # RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap, None]") + # [assignment] + self.data = reader # type: ignore[assignment] def read(self, rows=None): try: @@ -3727,7 +3756,11 @@ def __init__(self, f, **kwds): PythonParser.__init__(self, f, **kwds) def _make_reader(self, f): - self.data = FixedWidthReader( + # pandas\io\parsers.py:3730: error: Incompatible types in assignment + # (expression has type "FixedWidthReader", variable has type + # "Union[IO[Any], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, + # mmap, None]") [assignment] + self.data = FixedWidthReader( # type: ignore[assignment] f, self.colspecs, self.delimiter,