Skip to content
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

fix: fix -1 offset lookups failing #463

Merged
merged 2 commits into from
Mar 21, 2024
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
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
shobsi marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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 = 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