Skip to content

TYP: algos.isin #53479

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 1 commit into from
Jun 1, 2023
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
7 changes: 4 additions & 3 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

if TYPE_CHECKING:
from pandas._typing import (
ListLike,
NumpySorter,
NumpyValueArrayLike,
)
Expand Down Expand Up @@ -438,14 +439,14 @@ def unique_with_mask(values, mask: npt.NDArray[np.bool_] | None = None):
unique1d = unique


def isin(comps: AnyArrayLike, values: AnyArrayLike) -> npt.NDArray[np.bool_]:
def isin(comps: ListLike, values: ListLike) -> npt.NDArray[np.bool_]:
"""
Compute the isin boolean array.

Parameters
----------
comps : array-like
values : array-like
comps : list-like
values : list-like

Returns
-------
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,9 +1252,7 @@ def calc_with_mask(carg, mask):

# string with NaN-like
try:
# error: Argument 2 to "isin" has incompatible type "List[Any]"; expected
# "Union[Union[ExtensionArray, ndarray], Index, Series]"
mask = ~algorithms.isin(arg, list(nat_strings)) # type: ignore[arg-type]
mask = ~algorithms.isin(arg, list(nat_strings))
return calc_with_mask(arg, mask)
except (ValueError, OverflowError, TypeError):
pass
Expand Down
6 changes: 1 addition & 5 deletions pandas/io/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,7 @@ def _convert_to_ndarrays(
try:
values = lib.map_infer(values, conv_f)
except ValueError:
# error: Argument 2 to "isin" has incompatible type "List[Any]";
# expected "Union[Union[ExtensionArray, ndarray], Index, Series]"
mask = algorithms.isin(
values, list(na_values) # type: ignore[arg-type]
).view(np.uint8)
mask = algorithms.isin(values, list(na_values)).view(np.uint8)
values = lib.map_infer_mask(values, conv_f, mask)

cvals, na_count = self._infer_types(
Expand Down