Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

STY: ignore mypy errors #62482

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
mroeschke merged 7 commits into pandas-dev:main from Alvaro-Kothe:fix/mypy-errors
Sep 28, 2025
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

Some comments aren't visible on the classic Files Changed page.

3 changes: 1 addition & 2 deletions pandas/_typing.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@

# numpy compatible types
NumpyValueArrayLike: TypeAlias = ScalarLike_co | npt.ArrayLike
# Name "npt._ArrayLikeInt_co" is not defined [name-defined]
NumpySorter: TypeAlias = npt._ArrayLikeInt_co | None # type: ignore[name-defined]
NumpySorter: TypeAlias = npt._ArrayLikeInt_co | None


P = ParamSpec("P")
Expand Down
17 changes: 9 additions & 8 deletions pandas/core/algorithms.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,15 @@ def _reconstruct_data(
# that values.dtype == dtype
cls = dtype.construct_array_type()

# error: Incompatible types in assignment (expression has type
# "ExtensionArray", variable has type "ndarray[Any, Any]")
values = cls._from_sequence(values, dtype=dtype) # type: ignore[assignment]

else:
values = values.astype(dtype, copy=False)

return values
# error: Incompatible return value type
# (got "ExtensionArray",
# expected "ndarray[tuple[Any, ...], dtype[Any]]")
return cls._from_sequence(values, dtype=dtype) # type: ignore[return-value]

# error: Incompatible return value type
# (got "ndarray[tuple[Any, ...], dtype[Any]]",
# expected "ExtensionArray")
return values.astype(dtype, copy=False) # type: ignore[return-value]


def _ensure_arraylike(values, func_name: str) -> ArrayLike:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/array_algos/quantile.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def quantile_with_mask(
interpolation=interpolation,
)

result = np.asarray(result) # type: ignore[assignment]
result = np.asarray(result)
result = result.T

return result
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/arrays/_mixins.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ def view(self, dtype: Dtype | None = None) -> ArrayLike:

td64_values = arr.view(dtype)
return TimedeltaArray._simple_new(td64_values, dtype=dtype)
return arr.view(dtype=dtype)
# error: Argument "dtype" to "view" of "ndarray" has incompatible type
# "ExtensionDtype | dtype[Any]"; expected "dtype[Any] | _HasDType[dtype[Any]]"
return arr.view(dtype=dtype) # type: ignore[arg-type]

def take(
self,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/arrow/_arrow_utils.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def pyarrow_array_to_numpy_and_mask(
mask = pyarrow.BooleanArray.from_buffers(
pyarrow.bool_(), len(arr), [None, bitmask], offset=arr.offset
)
mask = np.asarray(mask) # type: ignore[assignment]
mask = np.asarray(mask)
else:
mask = np.ones(len(arr), dtype=bool)
return data, mask
4 changes: 2 additions & 2 deletions pandas/core/arrays/arrow/array.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def _box_pa_array(
):
arr_value = np.asarray(value, dtype=object)
# similar to isna(value) but exclude NaN, NaT, nat-like, nan-like
mask = is_pdna_or_none(arr_value) # type: ignore[assignment]
mask = is_pdna_or_none(arr_value)

try:
pa_array = pa.array(value, type=pa_type, mask=mask)
Expand Down Expand Up @@ -2738,7 +2738,7 @@ def _str_get_dummies(self, sep: str = "|", dtype: NpDtype | None = None):
dummies_dtype = np.bool_
dummies = np.zeros(n_rows * n_cols, dtype=dummies_dtype)
dummies[indices] = True
dummies = dummies.reshape((n_rows, n_cols)) # type: ignore[assignment]
dummies = dummies.reshape((n_rows, n_cols))
result = self._from_pyarrow_array(pa.array(list(dummies)))
return result, uniques_sorted.to_pylist()

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ def value_counts(self, dropna: bool = True) -> Series:
count = np.bincount(obs, minlength=ncat or 0)
else:
count = np.bincount(np.where(mask, code, ncat))
ix = np.append(ix, -1) # type: ignore[assignment]
ix = np.append(ix, -1)

ix = coerce_indexer_dtype(ix, self.dtype.categories)
ix_categorical = self._from_backing_data(ix)
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/arrays/datetimes.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,11 @@ def _add_offset(self, offset: BaseOffset) -> Self:
try:
res_values = offset._apply_array(values._ndarray)
if res_values.dtype.kind == "i":
res_values = res_values.view(values.dtype)
# error: Argument 1 to "view" of "ndarray" has
# incompatible type
# "dtype[datetime64[date | int | None]] | DatetimeTZDtype";
# expected "dtype[Any] | _HasDType[dtype[Any]]" [arg-type]
res_values = res_values.view(values.dtype) # type: ignore[arg-type]
except NotImplementedError:
if get_option("performance_warnings"):
warnings.warn(
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/string_.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def _cast_pointwise_result(self, values) -> ArrayLike:
result = super()._cast_pointwise_result(values)
if isinstance(result.dtype, StringDtype):
# Ensure we retain our same na_value/storage
result = result.astype(self.dtype) # type: ignore[call-overload]
result = result.astype(self.dtype)
return result

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/groupby.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ def _apply_filter(self, indices, dropna):
mask.fill(False)
mask[indices.astype(int)] = True
# mask fails to broadcast when passed to where; broadcast manually.
mask = np.tile(mask, list(self._selected_obj.shape[1:]) + [1]).T # type: ignore[assignment]
mask = np.tile(mask, list(self._selected_obj.shape[1:]) + [1]).T
filtered = self._selected_obj.where(mask) # Fill with NaNs.
return filtered

Expand Down
8 changes: 4 additions & 4 deletions pandas/core/indexers/objects.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def get_window_bounds(
if closed in ["left", "neither"]:
end -= 1

end = np.clip(end, 0, num_values) # type: ignore[assignment]
start = np.clip(start, 0, num_values) # type: ignore[assignment]
end = np.clip(end, 0, num_values)
start = np.clip(start, 0, num_values)

return start, end

Expand Down Expand Up @@ -402,7 +402,7 @@ def get_window_bounds(
start = np.arange(0, num_values, step, dtype="int64")
end = start + self.window_size
if self.window_size:
end = np.clip(end, 0, num_values) # type: ignore[assignment]
end = np.clip(end, 0, num_values)

return start, end

Expand Down Expand Up @@ -488,7 +488,7 @@ def get_window_bounds(
)
window_indices_start += len(indices)
# Extend as we'll be slicing window like [start, end)
window_indices = np.append(window_indices, [window_indices[-1] + 1]).astype( # type: ignore[assignment]
window_indices = np.append(window_indices, [window_indices[-1] + 1]).astype(
np.int64, copy=False
)
start_arrays.append(window_indices.take(ensure_platform_int(start)))
Expand Down
5 changes: 1 addition & 4 deletions pandas/core/methods/describe.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,11 @@ def _refine_percentiles(
if percentiles is None:
return np.array([0.25, 0.5, 0.75])

# explicit conversion of `percentiles` to list
percentiles = list(percentiles)
percentiles = np.asarray(percentiles)

# get them all to be in [0, 1]
validate_percentile(percentiles)

percentiles = np.asarray(percentiles)

# sort and check for duplicates
unique_pcts = np.unique(percentiles)
assert percentiles is not None
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/nanops.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,7 @@ def _mask_datetimelike_result(
# we need to apply the mask
result = result.astype("i8").view(orig_values.dtype)
axis_mask = mask.any(axis=axis)
# error: Unsupported target for indexed assignment ("Union[ndarray[Any, Any],
# datetime64, timedelta64]")
result[axis_mask] = iNaT # type: ignore[index]
result[axis_mask] = iNaT
else:
if mask.any():
return np.int64(iNaT).view(orig_values.dtype)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/encoding.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def get_empty_frame(data) -> DataFrame:

if drop_first:
# remove first GH12042
dummy_mat = dummy_mat[:, 1:] # type: ignore[assignment]
dummy_mat = dummy_mat[:, 1:]
dummy_cols = dummy_cols[1:]
return DataFrame(dummy_mat, index=index, columns=dummy_cols, dtype=_dtype)

Expand Down
8 changes: 6 additions & 2 deletions pandas/core/reshape/merge.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,9 @@ def _maybe_coerce_merge_keys(self) -> None:

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

mask = ~np.isnan(rk)
match = rk == casted
if not match[mask].all():
# error: Item "ExtensionArray" of
# "ExtensionArray | Any" has no attribute "all"
if not match[mask].all(): # type: ignore[union-attr]
warnings.warn(
"You are merging on int and float "
"columns where the float values "
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/util/hashing.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ def _hash_ndarray(
)

codes, categories = factorize(vals, sort=False)
dtype = CategoricalDtype(categories=Index(categories), ordered=False)
cat = Categorical._simple_new(codes, dtype)
tdtype = CategoricalDtype(categories=Index(categories), ordered=False)
cat = Categorical._simple_new(codes, tdtype)
return cat._hash_pandas_object(
encoding=encoding, hash_key=hash_key, categorize=False
)
Expand Down
13 changes: 5 additions & 8 deletions pandas/io/pytables.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3301,18 +3301,16 @@ def write_array(
# store as UTC
# with a zone

# error: Item "ExtensionArray" of "Union[Any, ExtensionArray]" has no
# attribute "asi8"
# error: "ExtensionArray" has no attribute "asi8"
self._handle.create_array(
self.group,
key,
value.asi8, # type: ignore[union-attr]
value.asi8, # type: ignore[attr-defined]
)

node = getattr(self.group, key)
# error: Item "ExtensionArray" of "Union[Any, ExtensionArray]" has no
# attribute "tz"
node._v_attrs.tz = _get_tz(value.tz) # type: ignore[union-attr]
# error: "ExtensionArray" has no attribute "tz"
node._v_attrs.tz = _get_tz(value.tz) # type: ignore[attr-defined]
node._v_attrs.value_type = f"datetime64[{value.dtype.unit}]"
elif lib.is_np_dtype(value.dtype, "m"):
self._handle.create_array(self.group, key, value.view("i8"))
Expand Down Expand Up @@ -5195,8 +5193,7 @@ def _maybe_convert_for_string_atom(
columns: list[str],
):
if isinstance(bvalues.dtype, StringDtype):
# "ndarray[Any, Any]" has no attribute "to_numpy"
bvalues = bvalues.to_numpy() # type: ignore[union-attr]
bvalues = bvalues.to_numpy()
if bvalues.dtype != object:
return bvalues

Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /