Skip to content

feat: allow assigning directly to Series.name property #495

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

Merged
merged 2 commits into from
Mar 22, 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
5 changes: 5 additions & 0 deletions bigframes/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def at(self) -> bigframes.core.indexers.AtSeriesIndexer:
def name(self) -> blocks.Label:
return self._name

@name.setter
def name(self, label: blocks.Label):
new_block = self._block.with_column_labels([label])
self._set_block(new_block)

@property
def shape(self) -> typing.Tuple[int]:
return (self._block.shape[0],)
Expand Down
15 changes: 15 additions & 0 deletions tests/system/small/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,21 @@ def test_empty_true_memtable(session: bigframes.Session):
assert bf_result == pd_result


def test_series_names(scalars_dfs):
scalars_df, scalars_pandas_df = scalars_dfs

bf_result = scalars_df["string_col"].copy()
bf_result.index.name = "new index name"
bf_result.name = "new series name"

pd_result = scalars_pandas_df["string_col"].copy()
pd_result.index.name = "new index name"
pd_result.name = "new series name"

assert pd_result.name == bf_result.name
assert pd_result.index.name == bf_result.index.name


def test_dtype(scalars_dfs):
scalars_df, scalars_pandas_df = scalars_dfs

Expand Down