Skip to content

TYP: Upgrade mypy to 1.0 #51204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ If installed, we now require:
+-------------------+-----------------+----------+---------+
| Package | Minimum Version | Required | Changed |
+===================+=================+==========+=========+
| mypy (dev) | 0.991 | | X |
| mypy (dev) | 1.0 | | X |
+-------------------+-----------------+----------+---------+
| pytest (dev) | 7.0.0 | | X |
+-------------------+-----------------+----------+---------+
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ dependencies:
- cpplint
- flake8=6.0.0
- isort>=5.2.1 # check that imports are in the right order
- mypy=0.991
- mypy=1.0
- pre-commit>=2.15.0
- pyupgrade
- ruff=0.0.215
Expand Down
5 changes: 1 addition & 4 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,7 @@ def __getitem__(self, item: PositionalIndexer):
elif isinstance(item, tuple):
item = unpack_tuple_and_ellipses(item)

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

Expand Down
6 changes: 4 additions & 2 deletions pandas/core/arrays/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ class BooleanArray(BaseMaskedArray):
# The value used to fill '_data' to avoid upcasting
_internal_fill_value = False
# Fill values used for any/all
_truthy_value = True
_falsey_value = False
# Incompatible types in assignment (expression has type "bool", base class
# "BaseMaskedArray" defined the type as "<typing special form>")
_truthy_value = True # type: ignore[assignment]
_falsey_value = False # type: ignore[assignment]
_TRUE_VALUES = {"True", "TRUE", "true", "1", "1.0"}
_FALSE_VALUES = {"False", "FALSE", "false", "0", "0.0"}

Expand Down
8 changes: 2 additions & 6 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2500,19 +2500,15 @@ def _generate_range(
# Argument 1 to "Timestamp" has incompatible type "Optional[Timestamp]";
# expected "Union[integer[Any], float, str, date, datetime64]"
start = Timestamp(start) # type: ignore[arg-type]
# Non-overlapping identity check (left operand type: "Timestamp", right
# operand type: "NaTType")
if start is not NaT: # type: ignore[comparison-overlap]
if start is not NaT:
start = start.as_unit(unit)
else:
start = None

# Argument 1 to "Timestamp" has incompatible type "Optional[Timestamp]";
# expected "Union[integer[Any], float, str, date, datetime64]"
end = Timestamp(end) # type: ignore[arg-type]
# Non-overlapping identity check (left operand type: "Timestamp", right
# operand type: "NaTType")
if end is not NaT: # type: ignore[comparison-overlap]
if end is not NaT:
end = end.as_unit(unit)
else:
end = None
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/arrays/floating.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ class FloatingArray(NumericArray):
# The value used to fill '_data' to avoid upcasting
_internal_fill_value = np.nan
# Fill values used for any/all
_truthy_value = 1.0
_falsey_value = 0.0
# Incompatible types in assignment (expression has type "float", base class
# "BaseMaskedArray" defined the type as "<typing special form>")
_truthy_value = 1.0 # type: ignore[assignment]
_falsey_value = 0.0 # type: ignore[assignment]


_dtype_docstring = """
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ class IntegerArray(NumericArray):
# The value used to fill '_data' to avoid upcasting
_internal_fill_value = 1
# Fill values used for any/all
_truthy_value = 1
_falsey_value = 0
# Incompatible types in assignment (expression has type "int", base class
# "BaseMaskedArray" defined the type as "<typing special form>")
_truthy_value = 1 # type: ignore[assignment]
_falsey_value = 0 # type: ignore[assignment]


_dtype_docstring = """
Expand Down
6 changes: 1 addition & 5 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,7 @@ def __getitem__(

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

if is_integer(key):
Expand Down
8 changes: 2 additions & 6 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,16 +787,12 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj,
elif isinstance(val, (np.datetime64, dt.datetime)):
try:
val = Timestamp(val)
# error: Non-overlapping identity check (left operand type:
# "Timestamp", right operand type: "NaTType")
if val is not NaT: # type: ignore[comparison-overlap]
if val is not NaT:
val = val.as_unit("ns")
except OutOfBoundsDatetime:
return _dtype_obj, val

# error: Non-overlapping identity check (left operand type: "Timestamp",
# right operand type: "NaTType")
if val is NaT or val.tz is None: # type: ignore[comparison-overlap]
if val is NaT or val.tz is None:
val = val.to_datetime64()
dtype = val.dtype
# TODO: test with datetime(2920, 10, 1) based on test_replace_dtypes
Expand Down
13 changes: 7 additions & 6 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2633,13 +2633,15 @@ def to_stata(
raise ValueError("strl is not supported in format 114")
from pandas.io.stata import StataWriter as statawriter
elif version == 117:
# mypy: Name 'statawriter' already defined (possibly by an import)
from pandas.io.stata import ( # type: ignore[no-redef]
# Incompatible import of "statawriter" (imported name has type
# "Type[StataWriter117]", local name has type "Type[StataWriter]")
from pandas.io.stata import ( # type: ignore[assignment]
StataWriter117 as statawriter,
)
else: # versions 118 and 119
# mypy: Name 'statawriter' already defined (possibly by an import)
from pandas.io.stata import ( # type: ignore[no-redef]
# Incompatible import of "statawriter" (imported name has type
# "Type[StataWriter117]", local name has type "Type[StataWriter]")
from pandas.io.stata import ( # type: ignore[assignment]
StataWriterUTF8 as statawriter,
)

Expand Down Expand Up @@ -5514,8 +5516,7 @@ def pop(self, item: Hashable) -> Series:
"""
return super().pop(item=item)

# error: Signature of "replace" incompatible with supertype "NDFrame"
@overload # type: ignore[override]
@overload
def replace(
self,
to_replace=...,
Expand Down
8 changes: 2 additions & 6 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,9 +1325,7 @@ def _maybe_coerce_merge_keys(self) -> None:

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

mask = ~np.isnan(rk)
match = rk == casted
# error: Item "ExtensionArray" of "Union[ExtensionArray,
# ndarray[Any, Any], Any]" has no attribute "all"
if not match[mask].all(): # type: ignore[union-attr]
if not match[mask].all():
warnings.warn(
"You are merging on int and float "
"columns where the float values "
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3370,8 +3370,7 @@ def update(self, other: Series | Sequence | Mapping) -> None:
# ----------------------------------------------------------------------
# Reindexing, sorting

# error: Signature of "sort_values" incompatible with supertype "NDFrame"
@overload # type: ignore[override]
@overload
def sort_values(
self,
*,
Expand Down Expand Up @@ -5131,8 +5130,7 @@ def pop(self, item: Hashable) -> Any:
"""
return super().pop(item=item)

# error: Signature of "replace" incompatible with supertype "NDFrame"
@overload # type: ignore[override]
@overload
def replace(
self,
to_replace=...,
Expand Down
4 changes: 3 additions & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,9 @@ def get_buffer(
raise ValueError("buf is not a file name and encoding is specified.")

if hasattr(buf, "write"):
yield buf
# Incompatible types in "yield" (actual type "Union[str, WriteBuffer[str],
# StringIO]", expected type "Union[WriteBuffer[str], StringIO]")
yield buf # type: ignore[misc]
elif isinstance(buf, str):
check_parent_directory(str(buf))
with open(buf, "w", encoding=encoding, newline="") as f:
Expand Down
7 changes: 1 addition & 6 deletions pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,12 +1138,7 @@ def _try_convert_data(
return data, False
return data.fillna(np.nan), True

# error: Non-overlapping identity check (left operand type:
# "Union[ExtensionDtype, str, dtype[Any], Type[object],
# Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any]],
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
# Type[object]]]]", right operand type: "Literal[True]")
elif self.dtype is True: # type: ignore[comparison-overlap]
elif self.dtype is True:
pass
else:
# dtype to force
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ black==22.10.0
cpplint
flake8==6.0.0
isort>=5.2.1
mypy==0.991
mypy==1.0
pre-commit>=2.15.0
pyupgrade
ruff==0.0.215
Expand Down