Skip to content

Commit

Permalink
feat: allow assigning directly to Series.name property (#495)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Sweña (Swast) <[email protected]>
  • Loading branch information
TrevorBergeron and tswast authored Mar 22, 2024
1 parent df2976f commit ad0e99e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit ad0e99e

Please sign in to comment.