Skip to content

Commit 61f0936

Browse files
authored
TYP: Upgrade mypy to 1.0 (#51204)
1 parent 11d856f commit 61f0936

File tree

15 files changed

+36
-53
lines changed

15 files changed

+36
-53
lines changed

doc/source/whatsnew/v2.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ If installed, we now require:
650650
+-------------------+-----------------+----------+---------+
651651
| Package | Minimum Version | Required | Changed |
652652
+===================+=================+==========+=========+
653-
| mypy (dev) | 0.991 | | X |
653+
| mypy (dev) | 1.0 | | X |
654654
+-------------------+-----------------+----------+---------+
655655
| pytest (dev) | 7.0.0 | | X |
656656
+-------------------+-----------------+----------+---------+

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ dependencies:
7979
- cpplint
8080
- flake8=6.0.0
8181
- isort>=5.2.1 # check that imports are in the right order
82-
- mypy=0.991
82+
- mypy=1.0
8383
- pre-commit>=2.15.0
8484
- pyupgrade
8585
- ruff=0.0.215

pandas/core/arrays/arrow/array.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,7 @@ def __getitem__(self, item: PositionalIndexer):
329329
elif isinstance(item, tuple):
330330
item = unpack_tuple_and_ellipses(item)
331331

332-
# error: Non-overlapping identity check (left operand type:
333-
# "Union[Union[int, integer[Any]], Union[slice, List[int],
334-
# ndarray[Any, Any]]]", right operand type: "ellipsis")
335-
if item is Ellipsis: # type: ignore[comparison-overlap]
332+
if item is Ellipsis:
336333
# TODO: should be handled by pyarrow?
337334
item = slice(None)
338335

pandas/core/arrays/boolean.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,10 @@ class BooleanArray(BaseMaskedArray):
288288
# The value used to fill '_data' to avoid upcasting
289289
_internal_fill_value = False
290290
# Fill values used for any/all
291-
_truthy_value = True
292-
_falsey_value = False
291+
# Incompatible types in assignment (expression has type "bool", base class
292+
# "BaseMaskedArray" defined the type as "<typing special form>")
293+
_truthy_value = True # type: ignore[assignment]
294+
_falsey_value = False # type: ignore[assignment]
293295
_TRUE_VALUES = {"True", "TRUE", "true", "1", "1.0"}
294296
_FALSE_VALUES = {"False", "FALSE", "false", "0", "0.0"}
295297

pandas/core/arrays/datetimes.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -2500,19 +2500,15 @@ def _generate_range(
25002500
# Argument 1 to "Timestamp" has incompatible type "Optional[Timestamp]";
25012501
# expected "Union[integer[Any], float, str, date, datetime64]"
25022502
start = Timestamp(start) # type: ignore[arg-type]
2503-
# Non-overlapping identity check (left operand type: "Timestamp", right
2504-
# operand type: "NaTType")
2505-
if start is not NaT: # type: ignore[comparison-overlap]
2503+
if start is not NaT:
25062504
start = start.as_unit(unit)
25072505
else:
25082506
start = None
25092507

25102508
# Argument 1 to "Timestamp" has incompatible type "Optional[Timestamp]";
25112509
# expected "Union[integer[Any], float, str, date, datetime64]"
25122510
end = Timestamp(end) # type: ignore[arg-type]
2513-
# Non-overlapping identity check (left operand type: "Timestamp", right
2514-
# operand type: "NaTType")
2515-
if end is not NaT: # type: ignore[comparison-overlap]
2511+
if end is not NaT:
25162512
end = end.as_unit(unit)
25172513
else:
25182514
end = None

pandas/core/arrays/floating.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ class FloatingArray(NumericArray):
116116
# The value used to fill '_data' to avoid upcasting
117117
_internal_fill_value = np.nan
118118
# Fill values used for any/all
119-
_truthy_value = 1.0
120-
_falsey_value = 0.0
119+
# Incompatible types in assignment (expression has type "float", base class
120+
# "BaseMaskedArray" defined the type as "<typing special form>")
121+
_truthy_value = 1.0 # type: ignore[assignment]
122+
_falsey_value = 0.0 # type: ignore[assignment]
121123

122124

123125
_dtype_docstring = """

pandas/core/arrays/integer.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ class IntegerArray(NumericArray):
132132
# The value used to fill '_data' to avoid upcasting
133133
_internal_fill_value = 1
134134
# Fill values used for any/all
135-
_truthy_value = 1
136-
_falsey_value = 0
135+
# Incompatible types in assignment (expression has type "int", base class
136+
# "BaseMaskedArray" defined the type as "<typing special form>")
137+
_truthy_value = 1 # type: ignore[assignment]
138+
_falsey_value = 0 # type: ignore[assignment]
137139

138140

139141
_dtype_docstring = """

pandas/core/arrays/sparse/array.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,7 @@ def __getitem__(
912912

913913
if isinstance(key, tuple):
914914
key = unpack_tuple_and_ellipses(key)
915-
# Non-overlapping identity check (left operand type:
916-
# "Union[Union[Union[int, integer[Any]], Union[slice, List[int],
917-
# ndarray[Any, Any]]], Tuple[Union[int, ellipsis], ...]]",
918-
# right operand type: "ellipsis")
919-
if key is Ellipsis: # type: ignore[comparison-overlap]
915+
if key is Ellipsis:
920916
raise ValueError("Cannot slice with Ellipsis")
921917

922918
if is_integer(key):

pandas/core/dtypes/cast.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -787,16 +787,12 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj,
787787
elif isinstance(val, (np.datetime64, dt.datetime)):
788788
try:
789789
val = Timestamp(val)
790-
# error: Non-overlapping identity check (left operand type:
791-
# "Timestamp", right operand type: "NaTType")
792-
if val is not NaT: # type: ignore[comparison-overlap]
790+
if val is not NaT:
793791
val = val.as_unit("ns")
794792
except OutOfBoundsDatetime:
795793
return _dtype_obj, val
796794

797-
# error: Non-overlapping identity check (left operand type: "Timestamp",
798-
# right operand type: "NaTType")
799-
if val is NaT or val.tz is None: # type: ignore[comparison-overlap]
795+
if val is NaT or val.tz is None:
800796
val = val.to_datetime64()
801797
dtype = val.dtype
802798
# TODO: test with datetime(2920, 10, 1) based on test_replace_dtypes

pandas/core/frame.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -2633,13 +2633,15 @@ def to_stata(
26332633
raise ValueError("strl is not supported in format 114")
26342634
from pandas.io.stata import StataWriter as statawriter
26352635
elif version == 117:
2636-
# mypy: Name 'statawriter' already defined (possibly by an import)
2637-
from pandas.io.stata import ( # type: ignore[no-redef]
2636+
# Incompatible import of "statawriter" (imported name has type
2637+
# "Type[StataWriter117]", local name has type "Type[StataWriter]")
2638+
from pandas.io.stata import ( # type: ignore[assignment]
26382639
StataWriter117 as statawriter,
26392640
)
26402641
else: # versions 118 and 119
2641-
# mypy: Name 'statawriter' already defined (possibly by an import)
2642-
from pandas.io.stata import ( # type: ignore[no-redef]
2642+
# Incompatible import of "statawriter" (imported name has type
2643+
# "Type[StataWriter117]", local name has type "Type[StataWriter]")
2644+
from pandas.io.stata import ( # type: ignore[assignment]
26432645
StataWriterUTF8 as statawriter,
26442646
)
26452647

@@ -5514,8 +5516,7 @@ def pop(self, item: Hashable) -> Series:
55145516
"""
55155517
return super().pop(item=item)
55165518

5517-
# error: Signature of "replace" incompatible with supertype "NDFrame"
5518-
@overload # type: ignore[override]
5519+
@overload
55195520
def replace(
55205521
self,
55215522
to_replace=...,

pandas/core/reshape/merge.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1325,9 +1325,7 @@ def _maybe_coerce_merge_keys(self) -> None:
13251325

13261326
mask = ~np.isnan(lk)
13271327
match = lk == casted
1328-
# error: Item "ExtensionArray" of "Union[ExtensionArray,
1329-
# ndarray[Any, Any], Any]" has no attribute "all"
1330-
if not match[mask].all(): # type: ignore[union-attr]
1328+
if not match[mask].all():
13311329
warnings.warn(
13321330
"You are merging on int and float "
13331331
"columns where the float values "
@@ -1347,9 +1345,7 @@ def _maybe_coerce_merge_keys(self) -> None:
13471345

13481346
mask = ~np.isnan(rk)
13491347
match = rk == casted
1350-
# error: Item "ExtensionArray" of "Union[ExtensionArray,
1351-
# ndarray[Any, Any], Any]" has no attribute "all"
1352-
if not match[mask].all(): # type: ignore[union-attr]
1348+
if not match[mask].all():
13531349
warnings.warn(
13541350
"You are merging on int and float "
13551351
"columns where the float values "

pandas/core/series.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -3370,8 +3370,7 @@ def update(self, other: Series | Sequence | Mapping) -> None:
33703370
# ----------------------------------------------------------------------
33713371
# Reindexing, sorting
33723372

3373-
# error: Signature of "sort_values" incompatible with supertype "NDFrame"
3374-
@overload # type: ignore[override]
3373+
@overload
33753374
def sort_values(
33763375
self,
33773376
*,
@@ -5131,8 +5130,7 @@ def pop(self, item: Hashable) -> Any:
51315130
"""
51325131
return super().pop(item=item)
51335132

5134-
# error: Signature of "replace" incompatible with supertype "NDFrame"
5135-
@overload # type: ignore[override]
5133+
@overload
51365134
def replace(
51375135
self,
51385136
to_replace=...,

pandas/io/formats/format.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,9 @@ def get_buffer(
12291229
raise ValueError("buf is not a file name and encoding is specified.")
12301230

12311231
if hasattr(buf, "write"):
1232-
yield buf
1232+
# Incompatible types in "yield" (actual type "Union[str, WriteBuffer[str],
1233+
# StringIO]", expected type "Union[WriteBuffer[str], StringIO]")
1234+
yield buf # type: ignore[misc]
12331235
elif isinstance(buf, str):
12341236
check_parent_directory(str(buf))
12351237
with open(buf, "w", encoding=encoding, newline="") as f:

pandas/io/json/_json.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1138,12 +1138,7 @@ def _try_convert_data(
11381138
return data, False
11391139
return data.fillna(np.nan), True
11401140

1141-
# error: Non-overlapping identity check (left operand type:
1142-
# "Union[ExtensionDtype, str, dtype[Any], Type[object],
1143-
# Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any]],
1144-
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
1145-
# Type[object]]]]", right operand type: "Literal[True]")
1146-
elif self.dtype is True: # type: ignore[comparison-overlap]
1141+
elif self.dtype is True:
11471142
pass
11481143
else:
11491144
# dtype to force

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ black==22.10.0
5656
cpplint
5757
flake8==6.0.0
5858
isort>=5.2.1
59-
mypy==0.991
59+
mypy==1.0
6060
pre-commit>=2.15.0
6161
pyupgrade
6262
ruff==0.0.215

0 commit comments

Comments
 (0)