|
15 | 15 | from __future__ import annotations |
16 | 16 |
|
17 | 17 | import typing |
18 | | -from typing import List, Sequence, Union |
| 18 | +from typing import Any, List, Sequence, Union |
19 | 19 |
|
20 | 20 | import bigframes_vendored.constants as constants |
21 | 21 | import bigframes_vendored.pandas.pandas._typing as vendored_pandas_typing |
|
34 | 34 | import bigframes.series as series |
35 | 35 | import bigframes.session |
36 | 36 |
|
| 37 | +_NO_NAME_SENTINEL = object() |
| 38 | + |
37 | 39 |
|
38 | 40 | class SeriesMethods: |
39 | 41 | def __init__( |
@@ -134,8 +136,17 @@ def __init__( |
134 | 136 | # If we didn't get a block make sure the name is what the user |
135 | 137 | # explicitly chose even if it is None. This is important for the |
136 | 138 | # 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]) |
139 | 150 |
|
140 | 151 | self._block: blocks.Block = block |
141 | 152 |
|
@@ -165,8 +176,7 @@ def _apply_unary_op( |
165 | 176 | block, result_id = self._block.apply_unary_op( |
166 | 177 | self._value_column, op, result_label=self._name |
167 | 178 | ) |
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) |
170 | 180 | return result |
171 | 181 |
|
172 | 182 | def _apply_binary_op( |
|
0 commit comments