Skip to content

TYP: fix ignores #40452

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 16 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
TYP: fix ignores
  • Loading branch information
jbrockmendel committed Mar 15, 2021
commit 411e3e372a468ef150888dde208c1f99510244a9
4 changes: 1 addition & 3 deletions pandas/core/array_algos/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ def re_replacer(s):
f = np.vectorize(re_replacer, otypes=[values.dtype])

if mask is None:
# error: Invalid index type "slice" for "ExtensionArray"; expected type
# "Union[int, ndarray]"
values[:] = f(values) # type: ignore[index]
values[:] = f(values)
else:
values[mask] = f(values[mask])
2 changes: 1 addition & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def __getitem__(
"""
raise AbstractMethodError(self)

def __setitem__(self, key: Union[int, np.ndarray], value: Any) -> None:
def __setitem__(self, key: Union[int, slice, np.ndarray], value: Any) -> None:
"""
Set one or more values inplace.

Expand Down
14 changes: 8 additions & 6 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Tuple,
Type,
Union,
cast,
)

import numpy as np
Expand Down Expand Up @@ -476,7 +477,7 @@ def _cmp_method(self, other, op):
# TODO(ARROW-9429): Add a .to_numpy() to ChunkedArray
return BooleanArray._from_sequence(result.to_pandas().values)

def __setitem__(self, key: Union[int, np.ndarray], value: Any) -> None:
def __setitem__(self, key: Union[int, slice, np.ndarray], value: Any) -> None:
"""Set one or more values inplace.

Parameters
Expand All @@ -500,6 +501,8 @@ def __setitem__(self, key: Union[int, np.ndarray], value: Any) -> None:
key = check_array_indexer(self, key)

if is_integer(key):
key = cast(int, key)

if not is_scalar(value):
raise ValueError("Must pass scalars with scalar indexer")
elif isna(value):
Expand All @@ -509,8 +512,7 @@ def __setitem__(self, key: Union[int, np.ndarray], value: Any) -> None:

# Slice data and insert in-between
new_data = [
# error: Slice index must be an integer or None
*self._data[0:key].chunks, # type: ignore[misc]
*self._data[0:key].chunks,
pa.array([value], type=pa.string()),
*self._data[(key + 1) :].chunks,
]
Expand All @@ -521,11 +523,11 @@ def __setitem__(self, key: Union[int, np.ndarray], value: Any) -> None:
# This is probably extremely slow.

# Convert all possible input key types to an array of integers
if is_bool_dtype(key):
if isinstance(key, slice):
key_array = np.array(range(len(self))[key])
elif is_bool_dtype(key):
# TODO(ARROW-9430): Directly support setitem(booleans)
key_array = np.argwhere(key).flatten()
elif isinstance(key, slice):
key_array = np.array(range(len(self))[key])
else:
# TODO(ARROW-9431): Directly support setitem(integers)
key_array = np.asanyarray(key)
Expand Down