Skip to content

Commit d02aea9

Browse files
committed
Backport PR pandas-dev#61265: TYP: Add ignores for numpy 2.2 updates
1 parent 9bb152d commit d02aea9

File tree

27 files changed

+42
-65
lines changed

27 files changed

+42
-65
lines changed

pandas/core/algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def _reconstruct_data(
209209
values = cls._from_sequence(values, dtype=dtype)
210210

211211
else:
212-
values = values.astype(dtype, copy=False)
212+
values = values.astype(dtype, copy=False) # type: ignore[assignment]
213213

214214
return values
215215

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 _nanpercentile(
196196
# Caller is responsible for ensuring mask shape match
197197
assert mask.shape == values.shape
198198
result = [
199-
_nanpercentile_1d(val, m, qs, na_value, interpolation=interpolation)
199+
_nanpercentile_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
@@ -141,18 +141,12 @@ def view(self, dtype: Dtype | None = None) -> ArrayLike:
141141

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

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

157151
def take(
158152
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
@@ -2499,7 +2499,7 @@ def _str_get_dummies(self, sep: str = "|"):
24992499
indices = indices + np.arange(n_rows).repeat(lengths) * n_cols
25002500
dummies = np.zeros(n_rows * n_cols, dtype=np.bool_)
25012501
dummies[indices] = True
2502-
dummies = dummies.reshape((n_rows, n_cols))
2502+
dummies = dummies.reshape((n_rows, n_cols)) # type: ignore[assignment]
25032503
result = type(self)(pa.array(list(dummies)))
25042504
return result, uniques_sorted.to_pylist()
25052505

pandas/core/arrays/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def to_numpy(
569569
if copy or na_value is not lib.no_default:
570570
result = result.copy()
571571
if na_value is not lib.no_default:
572-
result[self.isna()] = na_value
572+
result[self.isna()] = na_value # type: ignore[index]
573573
return result
574574

575575
# ------------------------------------------------------------------------

pandas/core/arrays/categorical.py

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

18441844
ix = coerce_indexer_dtype(ix, self.dtype.categories)
18451845
ix = self._from_backing_data(ix)

pandas/core/arrays/datetimes.py

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

323323
result = super()._simple_new(values, dtype)
324324
result._freq = freq
@@ -529,7 +529,7 @@ def _unbox_scalar(self, value) -> np.datetime64:
529529
raise ValueError("'value' should be a Timestamp.")
530530
self._check_compatible_with(value)
531531
if value is NaT:
532-
return np.datetime64(value._value, self.unit)
532+
return np.datetime64(value._value, self.unit) # type: ignore[call-overload]
533533
else:
534534
return value.as_unit(self.unit).asm8
535535

@@ -803,10 +803,7 @@ def _add_offset(self, offset: BaseOffset) -> Self:
803803
try:
804804
res_values = offset._apply_array(values._ndarray)
805805
if res_values.dtype.kind == "i":
806-
# error: Argument 1 to "view" of "ndarray" has incompatible type
807-
# "dtype[datetime64] | DatetimeTZDtype"; expected
808-
# "dtype[Any] | type[Any] | _SupportsDType[dtype[Any]]"
809-
res_values = res_values.view(values.dtype) # type: ignore[arg-type]
806+
res_values = res_values.view(values.dtype)
810807
except NotImplementedError:
811808
warnings.warn(
812809
"Non-vectorized DateOffset being applied to Series or DatetimeIndex.",

pandas/core/arrays/masked.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def tolist(self):
532532
if self.ndim > 1:
533533
return [x.tolist() for x in self]
534534
dtype = None if self._hasna else self._data.dtype
535-
return self.to_numpy(dtype=dtype, na_value=libmissing.NA).tolist()
535+
return self.to_numpy(dtype=dtype, na_value=libmissing.NA).tolist() # type: ignore[return-value]
536536

537537
@overload
538538
def astype(self, dtype: npt.DTypeLike, copy: bool = ...) -> np.ndarray:
@@ -1512,10 +1512,10 @@ def all(self, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs):
15121512
result = values.all(axis=axis)
15131513

15141514
if skipna:
1515-
return result
1515+
return result # type: ignore[return-value]
15161516
else:
15171517
if not result or len(self) == 0 or not self._mask.any():
1518-
return result
1518+
return result # type: ignore[return-value]
15191519
else:
15201520
return self.dtype.na_value
15211521

pandas/core/arrays/sparse/scipy_sparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _levels_to_axis(
7878
ax_coords = codes[valid_ilocs]
7979

8080
ax_labels = ax_labels.tolist()
81-
return ax_coords, ax_labels
81+
return ax_coords, ax_labels # pyright: ignore[reportReturnType]
8282

8383

8484
def _to_ijv(

0 commit comments

Comments
 (0)