Skip to content

Commit 758544d

Browse files
committed
Merge remote-tracking branch 'origin/main' into b405372623-read_gbq-allow_large_results
2 parents bfb4ca2 + e480d29 commit 758544d

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

bigframes/core/indexes/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ def unique(self, level: Hashable | int | None = None) -> Index:
504504
return self.get_level_values(level).drop_duplicates()
505505

506506
def isin(self, values) -> Index:
507+
import bigframes.series as series
508+
509+
if isinstance(values, (series.Series, Index)):
510+
return Index(self.to_series().isin(values))
507511
if not utils.is_list_like(values):
508512
raise TypeError(
509513
"only list-like objects are allowed to be passed to "

bigframes/series.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,10 @@ def nsmallest(self, n: int = 5, keep: str = "first") -> Series:
979979
)
980980

981981
def isin(self, values) -> "Series" | None:
982-
if isinstance(values, (Series,)):
982+
if isinstance(values, Series):
983983
return Series(self._block.isin(values._block))
984+
if isinstance(values, indexes.Index):
985+
return Series(self._block.isin(values.to_series()._block))
984986
if not _is_list_like(values):
985987
raise TypeError(
986988
"only list-like objects are allowed to be passed to "

tests/system/small/test_index.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def test_index_drop_duplicates(scalars_df_index, scalars_pandas_df_index, keep):
375375
)
376376

377377

378-
def test_index_isin(scalars_df_index, scalars_pandas_df_index):
378+
def test_index_isin_list(scalars_df_index, scalars_pandas_df_index):
379379
col_name = "int64_col"
380380
bf_series = (
381381
scalars_df_index.set_index(col_name).index.isin([2, 55555, 4]).to_pandas()
@@ -389,6 +389,38 @@ def test_index_isin(scalars_df_index, scalars_pandas_df_index):
389389
)
390390

391391

392+
def test_index_isin_bf_series(scalars_df_index, scalars_pandas_df_index, session):
393+
col_name = "int64_col"
394+
bf_series = (
395+
scalars_df_index.set_index(col_name)
396+
.index.isin(bpd.Series([2, 55555, 4], session=session))
397+
.to_pandas()
398+
)
399+
pd_result_array = scalars_pandas_df_index.set_index(col_name).index.isin(
400+
[2, 55555, 4]
401+
)
402+
pd.testing.assert_index_equal(
403+
pd.Index(pd_result_array).set_names(col_name),
404+
bf_series,
405+
)
406+
407+
408+
def test_index_isin_bf_index(scalars_df_index, scalars_pandas_df_index, session):
409+
col_name = "int64_col"
410+
bf_series = (
411+
scalars_df_index.set_index(col_name)
412+
.index.isin(bpd.Index([2, 55555, 4], session=session))
413+
.to_pandas()
414+
)
415+
pd_result_array = scalars_pandas_df_index.set_index(col_name).index.isin(
416+
[2, 55555, 4]
417+
)
418+
pd.testing.assert_index_equal(
419+
pd.Index(pd_result_array).set_names(col_name),
420+
bf_series,
421+
)
422+
423+
392424
def test_multiindex_name_is_none(session):
393425
df = pd.DataFrame(
394426
{

tests/system/small/test_series.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,24 @@ def test_isin_bigframes_values(scalars_dfs, col_name, test_set, session):
13801380
)
13811381

13821382

1383+
def test_isin_bigframes_index(scalars_dfs, session):
1384+
scalars_df, scalars_pandas_df = scalars_dfs
1385+
bf_result = (
1386+
scalars_df["string_col"]
1387+
.isin(bigframes.pandas.Index(["Hello, World!", "Hi", "こんにちは"], session=session))
1388+
.to_pandas()
1389+
)
1390+
pd_result = (
1391+
scalars_pandas_df["string_col"]
1392+
.isin(pd.Index(["Hello, World!", "Hi", "こんにちは"]))
1393+
.astype("boolean")
1394+
)
1395+
pd.testing.assert_series_equal(
1396+
pd_result,
1397+
bf_result,
1398+
)
1399+
1400+
13831401
@pytest.mark.parametrize(
13841402
(
13851403
"col_name",

0 commit comments

Comments
 (0)