Skip to content

Commit

Permalink
fix: fix -1 offset lookups failing (#463)
Browse files Browse the repository at this point in the history
* fix: fix -1 offset lookups failing

* parameterize series getitem int key test
  • Loading branch information
TrevorBergeron authored Mar 21, 2024
1 parent 23a8d9a commit 2dfb9c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bigframes/core/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 10 additions & 2 deletions tests/system/small/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,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 = 2
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)
Expand Down

0 comments on commit 2dfb9c2

Please sign in to comment.