Skip to content

Commit

Permalink
fix: Series iteration correctly returns values instead of index (#339)
Browse files Browse the repository at this point in the history
* fix: Series iteration correctly returns values instead of index

* Update iter docstring
  • Loading branch information
TrevorBergeron authored Jan 23, 2024
1 parent 4ff53db commit 2c6af9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bigframes/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __len__(self):

def __iter__(self) -> typing.Iterator:
return itertools.chain.from_iterable(
map(lambda x: x.index, self._block.to_pandas_batches())
map(lambda x: x.squeeze(axis=1), self._block.to_pandas_batches())
)

def copy(self) -> Series:
Expand Down
10 changes: 10 additions & 0 deletions tests/system/small/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2987,3 +2987,13 @@ def test_sample(scalars_dfs, frac, n, random_state):
n = 1 if n is None else n
expected_sample_size = round(frac * scalars_df.shape[0]) if frac is not None else n
assert bf_result.shape[0] == expected_sample_size


def test_series_iter(
scalars_df_index,
scalars_pandas_df_index,
):
for bf_i, pd_i in zip(
scalars_df_index["int64_too"], scalars_pandas_df_index["int64_too"]
):
assert bf_i == pd_i
12 changes: 6 additions & 6 deletions third_party/bigframes_vendored/pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def size(self) -> int:

def __iter__(self) -> Iterator:
"""
Iterate over info axis.
Iterate over column axis for DataFrame, or values for Series.
Returns
iterator: Info axis as iterator.
Returns:
iterator
**Examples:**
>>> import bigframes.pandas as bpd
Expand All @@ -71,9 +71,9 @@ def __iter__(self) -> Iterator:
>>> series = bpd.Series(["a", "b", "c"], index=[10, 20, 30])
>>> for x in series:
... print(x)
10
20
30
a
b
c
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

Expand Down

0 comments on commit 2c6af9b

Please sign in to comment.