From 03b51af2e7580fafe6ccc2d22fe1cfa0693a1a12 Mon Sep 17 00:00:00 2001 From: Ofsouzap Date: Sat, 9 Nov 2024 14:20:04 +0000 Subject: [PATCH 1/7] Fix indexing typing error --- pandas/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 08bd3cde60806..cbbfa208b33f9 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -914,7 +914,7 @@ def __setitem__(self, key, value) -> None: indexer = self._get_setitem_indexer(key) self._has_valid_setitem_indexer(key) - iloc = self if self.name == "iloc" else self.obj.iloc + iloc: _iLocIndexer = cast("_iLocIndexer", self) if self.name == "iloc" else self.obj.iloc iloc._setitem_with_indexer(indexer, value, self.name) def _validate_key(self, key, axis: AxisInt) -> None: From a36a34e5198ec090d7c680bdb71ca1edb636814f Mon Sep 17 00:00:00 2001 From: YasithDSL Date: Sat, 9 Nov 2024 14:59:25 +0000 Subject: [PATCH 2/7] add type ignore to column types --- pandas/tests/io/test_sql.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index c28a33069d23f..dcadd02a0caa2 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -237,14 +237,17 @@ def types_table_metadata(dialect: str): "types", metadata, Column("TextCol", TEXT), - Column("DateCol", date_type), + # error: Cannot infer type argument 1 of "Column" + Column("DateCol", date_type), # type: ignore[misc] Column("IntDateCol", Integer), Column("IntDateOnlyCol", Integer), Column("FloatCol", Float), Column("IntCol", Integer), - Column("BoolCol", bool_type), - Column("IntColWithNull", Integer), - Column("BoolColWithNull", bool_type), + # error: Cannot infer type argument 1 of "Column" + Column("BoolCol", bool_type), # type: ignore[misc] + Column("IntColWithNull", Integer), + # error: Cannot infer type argument 1 of "Column" + Column("BoolColWithNull", bool_type), # type: ignore[misc] ) return types From 5e2f18b9d24a7394431ac89d293fad7b6b3a8a08 Mon Sep 17 00:00:00 2001 From: Larry Date: Sat, 9 Nov 2024 16:20:47 +0000 Subject: [PATCH 3/7] type ignore common.py --- pandas/io/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/io/common.py b/pandas/io/common.py index 78fcdf8ff14b4..c91e698accd7c 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -910,12 +910,13 @@ def get_handle( or not hasattr(handle, "seekable") ): handle = _IOWrapper(handle) + # error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "_IOWrapper | BaseBuffer" [type-var] handle = TextIOWrapper( handle, encoding=ioargs.encoding, errors=errors, newline="", - ) + ) # type: ignore[arg-type] handles.append(handle) # only marked as wrapped when the caller provided a handle is_wrapped = not ( From 12aa2c8d85c74e6efd043fd10c3f254a06820e3e Mon Sep 17 00:00:00 2001 From: DL Lim Date: Sat, 9 Nov 2024 16:37:07 +0000 Subject: [PATCH 4/7] pre-commit --- pandas/core/dtypes/dtypes.py | 6 +++--- pandas/core/indexing.py | 4 +++- pandas/core/nanops.py | 4 +++- pandas/io/common.py | 2 +- pandas/plotting/_core.py | 4 ++-- pandas/tests/io/test_sql.py | 8 ++++---- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index ac46580a8cf30..96b0aa16940a6 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -2131,10 +2131,10 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None: stacklevel=find_stack_level(), ) np_dtypes = (x.subtype if isinstance(x, SparseDtype) else x for x in dtypes) - # error: Argument 1 to "np_find_common_type" has incompatible type - # "*Generator[Any | dtype[Any] | ExtensionDtype, None, None]"; + # error: Argument 1 to "np_find_common_type" has incompatible type + # "*Generator[Any | dtype[Any] | ExtensionDtype, None, None]"; # expected "dtype[Any]" [arg-type] - return SparseDtype(np_find_common_type(*np_dtypes), fill_value=fill_value) # type: ignore [arg-type] + return SparseDtype(np_find_common_type(*np_dtypes), fill_value=fill_value) # type: ignore [arg-type] @register_extension_dtype diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index cbbfa208b33f9..975e7ad135ba7 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -914,7 +914,9 @@ def __setitem__(self, key, value) -> None: indexer = self._get_setitem_indexer(key) self._has_valid_setitem_indexer(key) - iloc: _iLocIndexer = cast("_iLocIndexer", self) if self.name == "iloc" else self.obj.iloc + iloc: _iLocIndexer = ( + cast("_iLocIndexer", self) if self.name == "iloc" else self.obj.iloc + ) iloc._setitem_with_indexer(indexer, value, self.name) def _validate_key(self, key, axis: AxisInt) -> None: diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 1c35eacf55c03..d6154e2352c63 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -726,7 +726,9 @@ def nanmean( @bottleneck_switch() -def nanmedian(values: np.ndarray, *, axis: AxisInt | None = None, skipna: bool = True, mask=None) -> float | np.ndarray: +def nanmedian( + values: np.ndarray, *, axis: AxisInt | None = None, skipna: bool = True, mask=None +) -> float | np.ndarray: """ Parameters ---------- diff --git a/pandas/io/common.py b/pandas/io/common.py index c91e698accd7c..1f89afae19f89 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -916,7 +916,7 @@ def get_handle( encoding=ioargs.encoding, errors=errors, newline="", - ) # type: ignore[arg-type] + ) # type: ignore[arg-type] handles.append(handle) # only marked as wrapped when the caller provided a handle is_wrapped = not ( diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index 7a2796281cf5b..3fbd4c6f6e26a 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -1038,9 +1038,9 @@ def __call__(self, *args, **kwargs): label_name = label_kw or y data.name = label_name else: - # error: Argument 1 to "len" has incompatible type "Any | bool"; + # error: Argument 1 to "len" has incompatible type "Any | bool"; # expected "Sized" [arg-type] - match = is_list_like(label_kw) and len(label_kw) == len(y) # type: ignore[arg-type] + match = is_list_like(label_kw) and len(label_kw) == len(y) # type: ignore[arg-type] if label_kw and not match: raise ValueError( "label should be list-like and same length as y" diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index dcadd02a0caa2..beca8dea9407d 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -238,16 +238,16 @@ def types_table_metadata(dialect: str): metadata, Column("TextCol", TEXT), # error: Cannot infer type argument 1 of "Column" - Column("DateCol", date_type), # type: ignore[misc] + Column("DateCol", date_type), # type: ignore[misc] Column("IntDateCol", Integer), Column("IntDateOnlyCol", Integer), Column("FloatCol", Float), Column("IntCol", Integer), # error: Cannot infer type argument 1 of "Column" - Column("BoolCol", bool_type), # type: ignore[misc] - Column("IntColWithNull", Integer), + Column("BoolCol", bool_type), # type: ignore[misc] + Column("IntColWithNull", Integer), # error: Cannot infer type argument 1 of "Column" - Column("BoolColWithNull", bool_type), # type: ignore[misc] + Column("BoolColWithNull", bool_type), # type: ignore[misc] ) return types From c1d7a57454101101383ce7031ebca6b2a2a5ba02 Mon Sep 17 00:00:00 2001 From: Larry Date: Sat, 9 Nov 2024 16:41:07 +0000 Subject: [PATCH 5/7] fix line too long --- pandas/io/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/io/common.py b/pandas/io/common.py index c91e698accd7c..ceac59c850e94 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -910,7 +910,8 @@ def get_handle( or not hasattr(handle, "seekable") ): handle = _IOWrapper(handle) - # error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot be "_IOWrapper | BaseBuffer" [type-var] + # error: Value of type variable "_BufferT_co" of + # "TextIOWrapper" cannot be "_IOWrapper | BaseBuffer" [type-var] handle = TextIOWrapper( handle, encoding=ioargs.encoding, From 1ef6691c5bb111a06b05a1b37693afab2aefb188 Mon Sep 17 00:00:00 2001 From: DL Lim Date: Sat, 9 Nov 2024 17:00:33 +0000 Subject: [PATCH 6/7] pre-commit --- pandas/io/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/common.py b/pandas/io/common.py index bc6380fc59275..b4d35c159b1a1 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -910,7 +910,7 @@ def get_handle( or not hasattr(handle, "seekable") ): handle = _IOWrapper(handle) - # error: Value of type variable "_BufferT_co" of + # error: Value of type variable "_BufferT_co" of # "TextIOWrapper" cannot be "_IOWrapper | BaseBuffer" [type-var] handle = TextIOWrapper( handle, From 2a8019b0c93a276794ae0f01d8f1562441a5dda8 Mon Sep 17 00:00:00 2001 From: Nikolay Vasilev Date: Sat, 9 Nov 2024 17:24:49 +0000 Subject: [PATCH 7/7] Fixed type:ignore from type-arg to type-var --- pandas/io/common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/io/common.py b/pandas/io/common.py index b4d35c159b1a1..de70ed91c7dd4 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -910,10 +910,10 @@ def get_handle( or not hasattr(handle, "seekable") ): handle = _IOWrapper(handle) - # error: Value of type variable "_BufferT_co" of - # "TextIOWrapper" cannot be "_IOWrapper | BaseBuffer" [type-var] + # error: Value of type variable "_BufferT_co" of "TextIOWrapper" cannot + # be "_IOWrapper | BaseBuffer" [type-var] handle = TextIOWrapper( - handle, + handle, # type: ignore[type-var] encoding=ioargs.encoding, errors=errors, newline="",