Skip to content

Commit 9afda72

Browse files
authored
TYP: fix ignores (#41702)
1 parent 12e78f4 commit 9afda72

File tree

3 files changed

+15
-34
lines changed

3 files changed

+15
-34
lines changed

pandas/core/construction.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,8 @@ def sanitize_array(
551551
# TODO: copy?
552552
subarr = maybe_convert_platform(data)
553553
if subarr.dtype == object:
554-
# Argument 1 to "maybe_infer_to_datetimelike" has incompatible
555-
# type "Union[ExtensionArray, ndarray]"; expected "ndarray"
556-
subarr = maybe_infer_to_datetimelike(subarr) # type: ignore[arg-type]
554+
subarr = cast(np.ndarray, subarr)
555+
subarr = maybe_infer_to_datetimelike(subarr)
557556

558557
subarr = _sanitize_ndim(subarr, data, dtype, index, allow_2d=allow_2d)
559558

@@ -617,9 +616,7 @@ def _sanitize_ndim(
617616
if is_object_dtype(dtype) and isinstance(dtype, ExtensionDtype):
618617
# i.e. PandasDtype("O")
619618

620-
# error: Argument "dtype" to "asarray_tuplesafe" has incompatible type
621-
# "Type[object]"; expected "Union[str, dtype[Any], None]"
622-
result = com.asarray_tuplesafe(data, dtype=object) # type: ignore[arg-type]
619+
result = com.asarray_tuplesafe(data, dtype=np.dtype("object"))
623620
cls = dtype.construct_array_type()
624621
result = cls._from_sequence(result, dtype=dtype)
625622
else:

pandas/core/dtypes/cast.py

+8-18
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ def maybe_convert_platform(
123123
arr = values
124124

125125
if arr.dtype == object:
126-
# error: Argument 1 to "maybe_convert_objects" has incompatible type
127-
# "Union[ExtensionArray, ndarray]"; expected "ndarray"
128-
arr = lib.maybe_convert_objects(arr) # type: ignore[arg-type]
126+
arr = cast(np.ndarray, arr)
127+
arr = lib.maybe_convert_objects(arr)
129128

130129
return arr
131130

@@ -1249,13 +1248,12 @@ def astype_array(values: ArrayLike, dtype: DtypeObj, copy: bool = False) -> Arra
12491248
return values.copy()
12501249
return values
12511250

1252-
if isinstance(values, ABCExtensionArray):
1251+
if not isinstance(values, np.ndarray):
1252+
# i.e. ExtensionArray
12531253
values = values.astype(dtype, copy=copy)
12541254

12551255
else:
1256-
# error: Argument 1 to "astype_nansafe" has incompatible type "ExtensionArray";
1257-
# expected "ndarray"
1258-
values = astype_nansafe(values, dtype, copy=copy) # type: ignore[arg-type]
1256+
values = astype_nansafe(values, dtype, copy=copy)
12591257

12601258
# in pandas we don't store numpy str dtypes, so convert to object
12611259
if isinstance(dtype, np.dtype) and issubclass(values.dtype.type, str):
@@ -1975,7 +1973,7 @@ def construct_1d_object_array_from_listlike(values: Sized) -> np.ndarray:
19751973

19761974

19771975
def construct_1d_ndarray_preserving_na(
1978-
values: Sequence, dtype: DtypeObj | None = None, copy: bool = False
1976+
values: Sequence, dtype: np.dtype | None = None, copy: bool = False
19791977
) -> np.ndarray:
19801978
"""
19811979
Construct a new ndarray, coercing `values` to `dtype`, preserving NA.
@@ -2020,17 +2018,9 @@ def construct_1d_ndarray_preserving_na(
20202018
and isinstance(values, np.ndarray)
20212019
and values.dtype.kind == "f"
20222020
):
2023-
# Argument 2 to "astype_float_to_int_nansafe" has incompatible
2024-
# type "Union[dtype[Any], ExtensionDtype]"; expected "dtype[Any]"
2025-
return astype_float_to_int_nansafe(
2026-
values, dtype, copy=copy # type: ignore[arg-type]
2027-
)
2021+
return astype_float_to_int_nansafe(values, dtype, copy=copy)
20282022
else:
2029-
# error: Argument "dtype" to "array" has incompatible type
2030-
# "Union[dtype[Any], ExtensionDtype, None]"; expected "Union[dtype[Any],
2031-
# None, type, _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any,
2032-
# Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]"
2033-
subarr = np.array(values, dtype=dtype, copy=copy) # type: ignore[arg-type]
2023+
subarr = np.array(values, dtype=dtype, copy=copy)
20342024

20352025
return subarr
20362026

pandas/core/indexes/interval.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,8 @@ def interval_range(
11651165
if periods is not None:
11661166
periods += 1
11671167

1168+
breaks: np.ndarray | TimedeltaIndex | DatetimeIndex
1169+
11681170
if is_number(endpoint):
11691171
# force consistency between start/end/freq (lower end if freq skips it)
11701172
if com.all_not_none(start, end, freq):
@@ -1190,16 +1192,8 @@ def interval_range(
11901192
else:
11911193
# delegate to the appropriate range function
11921194
if isinstance(endpoint, Timestamp):
1193-
# error: Incompatible types in assignment (expression has type
1194-
# "DatetimeIndex", variable has type "ndarray")
1195-
breaks = date_range( # type: ignore[assignment]
1196-
start=start, end=end, periods=periods, freq=freq
1197-
)
1195+
breaks = date_range(start=start, end=end, periods=periods, freq=freq)
11981196
else:
1199-
# error: Incompatible types in assignment (expression has type
1200-
# "TimedeltaIndex", variable has type "ndarray")
1201-
breaks = timedelta_range( # type: ignore[assignment]
1202-
start=start, end=end, periods=periods, freq=freq
1203-
)
1197+
breaks = timedelta_range(start=start, end=end, periods=periods, freq=freq)
12041198

12051199
return IntervalIndex.from_breaks(breaks, name=name, closed=closed)

0 commit comments

Comments
 (0)