Skip to content

Commit adec21f

Browse files
authored
TYP: Add ignores for numpy 2.2 updates (#61265)
* TYP: Add ignores for numpy 2.2 updates * fix tests and plotting * ignore pyright error
1 parent 4b8c472 commit adec21f

File tree

28 files changed

+43
-63
lines changed

28 files changed

+43
-63
lines changed

pandas/core/algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def _reconstruct_data(
215215
values = cls._from_sequence(values, dtype=dtype) # type: ignore[assignment]
216216

217217
else:
218-
values = values.astype(dtype, copy=False)
218+
values = values.astype(dtype, copy=False) # type: ignore[assignment]
219219

220220
return values
221221

pandas/core/array_algos/quantile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def quantile_with_mask(
102102
interpolation=interpolation,
103103
)
104104

105-
result = np.asarray(result)
105+
result = np.asarray(result) # type: ignore[assignment]
106106
result = result.T
107107

108108
return result
@@ -196,7 +196,7 @@ def _nanquantile(
196196
# Caller is responsible for ensuring mask shape match
197197
assert mask.shape == values.shape
198198
result = [
199-
_nanquantile_1d(val, m, qs, na_value, interpolation=interpolation)
199+
_nanquantile_1d(val, m, qs, na_value, interpolation=interpolation) # type: ignore[arg-type]
200200
for (val, m) in zip(list(values), list(mask))
201201
]
202202
if values.dtype.kind == "f":

pandas/core/arrays/_mixins.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,12 @@ def view(self, dtype: Dtype | None = None) -> ArrayLike:
142142

143143
dt64_values = arr.view(dtype)
144144
return DatetimeArray._simple_new(dt64_values, dtype=dtype)
145-
146145
elif lib.is_np_dtype(dtype, "m") and is_supported_dtype(dtype):
147146
from pandas.core.arrays import TimedeltaArray
148147

149148
td64_values = arr.view(dtype)
150149
return TimedeltaArray._simple_new(td64_values, dtype=dtype)
151-
152-
# error: Argument "dtype" to "view" of "_ArrayOrScalarCommon" has incompatible
153-
# type "Union[ExtensionDtype, dtype[Any]]"; expected "Union[dtype[Any], None,
154-
# type, _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any, Union[int,
155-
# Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]"
156-
return arr.view(dtype=dtype) # type: ignore[arg-type]
150+
return arr.view(dtype=dtype)
157151

158152
def take(
159153
self,

pandas/core/arrays/arrow/_arrow_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def pyarrow_array_to_numpy_and_mask(
4444
mask = pyarrow.BooleanArray.from_buffers(
4545
pyarrow.bool_(), len(arr), [None, bitmask], offset=arr.offset
4646
)
47-
mask = np.asarray(mask)
47+
mask = np.asarray(mask) # type: ignore[assignment]
4848
else:
4949
mask = np.ones(len(arr), dtype=bool)
5050
return data, mask

pandas/core/arrays/arrow/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ def _str_get_dummies(self, sep: str = "|", dtype: NpDtype | None = None):
25402540
dummies_dtype = np.bool_
25412541
dummies = np.zeros(n_rows * n_cols, dtype=dummies_dtype)
25422542
dummies[indices] = True
2543-
dummies = dummies.reshape((n_rows, n_cols))
2543+
dummies = dummies.reshape((n_rows, n_cols)) # type: ignore[assignment]
25442544
result = type(self)(pa.array(list(dummies)))
25452545
return result, uniques_sorted.to_pylist()
25462546

pandas/core/arrays/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def to_numpy(
596596
if copy or na_value is not lib.no_default:
597597
result = result.copy()
598598
if na_value is not lib.no_default:
599-
result[self.isna()] = na_value
599+
result[self.isna()] = na_value # type: ignore[index]
600600
return result
601601

602602
# ------------------------------------------------------------------------

pandas/core/arrays/categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ def value_counts(self, dropna: bool = True) -> Series:
18531853
count = np.bincount(obs, minlength=ncat or 0)
18541854
else:
18551855
count = np.bincount(np.where(mask, code, ncat))
1856-
ix = np.append(ix, -1)
1856+
ix = np.append(ix, -1) # type: ignore[assignment]
18571857

18581858
ix = coerce_indexer_dtype(ix, self.dtype.categories)
18591859
ix_categorical = self._from_backing_data(ix)

pandas/core/arrays/datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,7 @@ def take(
23942394
)
23952395

23962396
indices = np.asarray(indices, dtype=np.intp)
2397-
maybe_slice = lib.maybe_indices_to_slice(indices, len(self))
2397+
maybe_slice = lib.maybe_indices_to_slice(indices, len(self)) # type: ignore[arg-type]
23982398

23992399
if isinstance(maybe_slice, slice):
24002400
freq = self._get_getitem_freq(maybe_slice)

pandas/core/arrays/datetimes.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _simple_new( # type: ignore[override]
331331
else:
332332
# DatetimeTZDtype. If we have e.g. DatetimeTZDtype[us, UTC],
333333
# then values.dtype should be M8[us].
334-
assert dtype._creso == get_unit_from_dtype(values.dtype)
334+
assert dtype._creso == get_unit_from_dtype(values.dtype) # type: ignore[union-attr]
335335

336336
result = super()._simple_new(values, dtype)
337337
result._freq = freq
@@ -542,7 +542,7 @@ def _unbox_scalar(self, value) -> np.datetime64:
542542
raise ValueError("'value' should be a Timestamp.")
543543
self._check_compatible_with(value)
544544
if value is NaT:
545-
return np.datetime64(value._value, self.unit)
545+
return np.datetime64(value._value, self.unit) # type: ignore[call-overload]
546546
else:
547547
return value.as_unit(self.unit, round_ok=False).asm8
548548

@@ -813,10 +813,7 @@ def _add_offset(self, offset: BaseOffset) -> Self:
813813
try:
814814
res_values = offset._apply_array(values._ndarray)
815815
if res_values.dtype.kind == "i":
816-
# error: Argument 1 to "view" of "ndarray" has incompatible type
817-
# "dtype[datetime64] | DatetimeTZDtype"; expected
818-
# "dtype[Any] | type[Any] | _SupportsDType[dtype[Any]]"
819-
res_values = res_values.view(values.dtype) # type: ignore[arg-type]
816+
res_values = res_values.view(values.dtype)
820817
except NotImplementedError:
821818
if get_option("performance_warnings"):
822819
warnings.warn(

pandas/core/arrays/masked.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def tolist(self) -> list:
515515
if self.ndim > 1:
516516
return [x.tolist() for x in self]
517517
dtype = None if self._hasna else self._data.dtype
518-
return self.to_numpy(dtype=dtype, na_value=libmissing.NA).tolist()
518+
return self.to_numpy(dtype=dtype, na_value=libmissing.NA).tolist() # type: ignore[return-value]
519519

520520
@overload
521521
def astype(self, dtype: npt.DTypeLike, copy: bool = ...) -> np.ndarray: ...
@@ -1497,10 +1497,10 @@ def all(
14971497
result = values.all(axis=axis)
14981498

14991499
if skipna:
1500-
return result
1500+
return result # type: ignore[return-value]
15011501
else:
15021502
if not result or len(self) == 0 or not self._mask.any():
1503-
return result
1503+
return result # type: ignore[return-value]
15041504
else:
15051505
return self.dtype.na_value
15061506

0 commit comments

Comments
 (0)