Skip to content

Commit 171f3ec

Browse files
committed
disambiguate explicit names
1 parent fbe606e commit 171f3ec

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

bigframes/operations/base.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616

1717
import typing
18-
from typing import List, Sequence, Union
18+
from typing import Any, List, Sequence, Union
1919

2020
import bigframes_vendored.constants as constants
2121
import bigframes_vendored.pandas.pandas._typing as vendored_pandas_typing
@@ -34,6 +34,8 @@
3434
import bigframes.series as series
3535
import bigframes.session
3636

37+
_NO_NAME_SENTINEL = object()
38+
3739

3840
class SeriesMethods:
3941
def __init__(
@@ -134,8 +136,17 @@ def __init__(
134136
# If we didn't get a block make sure the name is what the user
135137
# explicitly chose even if it is None. This is important for the
136138
# polars backend where the implicit column labels are integers.
137-
if not isinstance(data, blocks.Block):
138-
block = block.with_column_labels([name or getattr(data, "name", None)])
139+
if name:
140+
default_name: Any = name
141+
elif hasattr(data, "name"):
142+
default_name = getattr(data, "name", None)
143+
elif hasattr(data, "_name"):
144+
default_name = getattr(data, "_name", None)
145+
else:
146+
default_name = _NO_NAME_SENTINEL
147+
148+
if default_name is not _NO_NAME_SENTINEL:
149+
block = block.with_column_labels([default_name])
139150

140151
self._block: blocks.Block = block
141152

@@ -165,8 +176,7 @@ def _apply_unary_op(
165176
block, result_id = self._block.apply_unary_op(
166177
self._value_column, op, result_label=self._name
167178
)
168-
result = series.Series(block.select_column(result_id))
169-
result.name = getattr(self, "name", None)
179+
result = series.Series(block.select_column(result_id), name=self._name)
170180
return result
171181

172182
def _apply_binary_op(

0 commit comments

Comments
 (0)