8000 fix: Series iteration correctly returns values instead of index by TrevorBergeron · Pull Request #339 · googleapis/python-bigquery-dataframes · GitHub
[go: up one dir, main page]

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