From 5fe145b44e4d3d311b32d65cedc9b8ab5c117ba4 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Tue, 19 Mar 2024 00:33:14 +0000 Subject: [PATCH 1/2] fix: fix -1 offset lookups failing --- bigframes/core/indexers.py | 3 ++- tests/system/small/test_series.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bigframes/core/indexers.py b/bigframes/core/indexers.py index 8d6a1cbdfe..da6f3f3740 100644 --- a/bigframes/core/indexers.py +++ b/bigframes/core/indexers.py @@ -402,7 +402,8 @@ def _iloc_getitem_series_or_dataframe( pd.Series, ]: if isinstance(key, int): - internal_slice_result = series_or_dataframe._slice(key, key + 1, 1) + stop_key = key + 1 if key != -1 else None + internal_slice_result = series_or_dataframe._slice(key, stop_key, 1) result_pd_df = internal_slice_result.to_pandas() if result_pd_df.empty: raise IndexError("single positional indexer is out-of-bounds") diff --git a/tests/system/small/test_series.py b/tests/system/small/test_series.py index dcb47d8c60..e1c44f9342 100644 --- a/tests/system/small/test_series.py +++ b/tests/system/small/test_series.py @@ -216,7 +216,7 @@ def test_series___getitem__(scalars_dfs, index_col, key): def test_series___getitem___with_int_key(scalars_dfs): col_name = "int64_too" index_col = "string_col" - key = 2 + key = -1 scalars_df, scalars_pandas_df = scalars_dfs scalars_df = scalars_df.set_index(index_col, drop=False) scalars_pandas_df = scalars_pandas_df.set_index(index_col, drop=False) From 469110ae94b7c263530b3b58719dbb99032ada10 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Wed, 20 Mar 2024 19:24:43 +0000 Subject: [PATCH 2/2] parameterize series getitem int key test --- tests/system/small/test_series.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/system/small/test_series.py b/tests/system/small/test_series.py index e1c44f9342..de3ccdc14a 100644 --- a/tests/system/small/test_series.py +++ b/tests/system/small/test_series.py @@ -213,10 +213,18 @@ def test_series___getitem__(scalars_dfs, index_col, key): pd.testing.assert_series_equal(bf_result.to_pandas(), pd_result) -def test_series___getitem___with_int_key(scalars_dfs): +@pytest.mark.parametrize( + ("key",), + ( + (-2,), + (-1,), + (0,), + (1,), + ), +) +def test_series___getitem___with_int_key(scalars_dfs, key): col_name = "int64_too" index_col = "string_col" - key = -1 scalars_df, scalars_pandas_df = scalars_dfs scalars_df = scalars_df.set_index(index_col, drop=False) scalars_pandas_df = scalars_pandas_df.set_index(index_col, drop=False)