Skip to content

Commit ee06333

Browse files
committed
type isin, remove redundant Iterable | Series
1 parent 4b1436f commit ee06333

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
17831783
axis: Axis = 0,
17841784
copy: _bool = True,
17851785
) -> Self: ...
1786-
def isin(self, values: Iterable | Series | DataFrame | dict) -> Self: ...
1786+
def isin(
1787+
self, values: Iterable | DataFrame | Mapping[Hashable, Iterable]
1788+
) -> Self: ...
17871789
@property
17881790
def plot(self) -> PlotAccessor: ...
17891791
def hist(

pandas-stubs/core/indexes/base.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
554554
@final
555555
def get_indexer_for(self, target, **kwargs: Any): ...
556556
def map(self, mapper, na_action=...) -> Index: ...
557-
def isin(self, values, level=...) -> np_1darray_bool: ...
557+
def isin(self, values: Iterable, level: Level | None = None) -> np_1darray_bool: ...
558558
def slice_indexer(
559559
self,
560560
start: Label | None = None,

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
13021302
show_counts: bool | None = ...,
13031303
) -> None: ...
13041304
def memory_usage(self, index: _bool = True, deep: _bool = False) -> int: ...
1305-
def isin(self, values: Iterable | Series[S1] | dict) -> Series[_bool]: ...
1305+
def isin(self, values: Iterable) -> Series[_bool]: ...
13061306
def between(
13071307
self,
13081308
left: Scalar | ListLikeU,

tests/indexes/test_indexes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ def test_index_duplicated() -> None:
5656

5757
def test_index_isin() -> None:
5858
ind = pd.Index([1, 2, 3, 4, 5])
59-
isin = ind.isin([2, 4])
60-
check(assert_type(isin, np_1darray_bool), np_1darray_bool)
59+
check(assert_type(ind.isin([2, 4]), np_1darray_bool), np_1darray_bool)
60+
check(assert_type(ind.isin({2, 4}), np_1darray_bool), np_1darray_bool)
61+
check(assert_type(ind.isin(pd.Series([2, 4])), np_1darray_bool), np_1darray_bool)
62+
check(assert_type(ind.isin(pd.Index([2, 4])), np_1darray_bool), np_1darray_bool)
6163

6264

6365
def test_index_astype() -> None:

tests/series/test_series.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,16 @@ def test_series_min_max_sub_axis() -> None:
16101610
check(assert_type(df.max(axis=1), pd.Series), pd.Series)
16111611

16121612

1613+
def test_series_isin() -> None:
1614+
s = pd.Series([1, 2, 3, 4, 5])
1615+
check(assert_type(s.isin([3, 4]), "pd.Series[bool]"), pd.Series, np.bool_)
1616+
check(assert_type(s.isin({3, 4}), "pd.Series[bool]"), pd.Series, np.bool_)
1617+
check(
1618+
assert_type(s.isin(pd.Series([3, 4])), "pd.Series[bool]"), pd.Series, np.bool_
1619+
)
1620+
check(assert_type(s.isin(pd.Index([3, 4])), "pd.Series[bool]"), pd.Series, np.bool_)
1621+
1622+
16131623
def test_series_index_isin() -> None:
16141624
s = pd.Series([1, 2, 3, 4, 5], index=[1, 2, 2, 3, 3])
16151625
t1 = s.loc[s.index.isin([1, 3])]

tests/test_frame.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,6 +2940,16 @@ def test_getmultiindex_columns() -> None:
29402940
check(assert_type(df[li[0]], pd.Series), pd.Series)
29412941

29422942

2943+
def test_frame_isin() -> None:
2944+
df = pd.DataFrame({"x": [1, 2, 3, 4, 5]}, index=[1, 2, 3, 4, 5])
2945+
check(assert_type(df.isin([1, 3, 5]), pd.DataFrame), pd.DataFrame)
2946+
check(assert_type(df.isin({1, 3, 5}), pd.DataFrame), pd.DataFrame)
2947+
check(assert_type(df.isin(pd.Series([1, 3, 5])), pd.DataFrame), pd.DataFrame)
2948+
check(assert_type(df.isin(pd.Index([1, 3, 5])), pd.DataFrame), pd.DataFrame)
2949+
check(assert_type(df.isin(df), pd.DataFrame), pd.DataFrame)
2950+
check(assert_type(df.isin({"x": [1, 2]}), pd.DataFrame), pd.DataFrame)
2951+
2952+
29432953
def test_frame_getitem_isin() -> None:
29442954
df = pd.DataFrame({"x": [1, 2, 3, 4, 5]}, index=[1, 2, 3, 4, 5])
29452955
check(assert_type(df[df.index.isin([1, 3, 5])], pd.DataFrame), pd.DataFrame)

0 commit comments

Comments
 (0)