Skip to content

Commit d80bfcb

Browse files
committed
fix TestSession read_pandas for Series
1 parent ddbb32d commit d80bfcb

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

bigframes/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ def _getitem_label(self, key: blocks.Label):
688688
return DataFrame(block)
689689

690690
if len(col_ids) == 1:
691-
return bigframes.series.Series(block, name=key)
691+
return bigframes.series.Series(block)
692692
return DataFrame(block)
693693

694694
# Bool Series selects rows

bigframes/operations/base.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from __future__ import annotations
1616

17-
import enum
1817
import typing
1918
from typing import List, Sequence, Union
2019

@@ -36,18 +35,6 @@
3635
import bigframes.session
3736

3837

39-
class Default(enum.Enum):
40-
"""Sentinel that can disambiguate explicit None from missing.
41-
42-
See https://stackoverflow.com/a/76606310/101923
43-
"""
44-
45-
token = 0
46-
47-
48-
DEFAULT = Default.token
49-
50-
5138
class SeriesMethods:
5239
def __init__(
5340
self,
@@ -56,7 +43,7 @@ def __init__(
5643
dtype: typing.Optional[
5744
bigframes.dtypes.DtypeString | bigframes.dtypes.Dtype
5845
] = None,
59-
name: str | None | Default = DEFAULT,
46+
name: str | None = None,
6047
copy: typing.Optional[bool] = None,
6148
*,
6249
session: typing.Optional[bigframes.session.Session] = None,
@@ -120,7 +107,6 @@ def __init__(
120107
block = data_block
121108

122109
if block:
123-
# Data was a bigframes object.
124110
assert len(block.value_columns) == 1
125111
assert len(block.column_labels) == 1
126112
if index is not None: # reindexing operation
@@ -129,27 +115,23 @@ def __init__(
129115
idx_cols = idx_block.index_columns
130116
block, _ = idx_block.join(block, how="left")
131117
block = block.with_index_labels(bf_index.names)
132-
if name is not DEFAULT:
118+
if name:
133119
block = block.with_column_labels([name])
134120
if dtype:
135121
bf_dtype = bigframes.dtypes.bigframes_type(dtype)
136122
block = block.multi_apply_unary_op(ops.AsTypeOp(to_type=bf_dtype))
137123
else:
138-
# Data was local.
139124
if isinstance(dtype, str) and dtype.lower() == "json":
140125
dtype = bigframes.dtypes.JSON_DTYPE
141126
pd_series = pd.Series(
142127
data=data,
143128
index=index, # type:ignore
144129
dtype=dtype, # type:ignore
145-
name=name if name is not DEFAULT else None,
130+
name=name,
146131
)
147-
name = pd_series.name # type: ignore
148132
block = read_pandas_func(pd_series)._get_block() # type:ignore
149-
block = block.with_column_labels([name])
150133

151134
assert block is not None
152-
153135
self._block: blocks.Block = block
154136

155137
@property
@@ -178,8 +160,7 @@ def _apply_unary_op(
178160
block, result_id = self._block.apply_unary_op(
179161
self._value_column, op, result_label=self._name
180162
)
181-
result = series.Series(block.select_column(result_id), name=self._name)
182-
return result
163+
return series.Series(block.select_column(result_id))
183164

184165
def _apply_binary_op(
185166
self,

bigframes/testing/polars_session.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,23 @@ def __init__(self):
9494
self._loader = None # type: ignore
9595

9696
def read_pandas(self, pandas_dataframe, write_engine="default"):
97+
original_input = pandas_dataframe
98+
9799
# override read_pandas to always keep data local-only
98100
if isinstance(pandas_dataframe, (pandas.Series, pandas.Index)):
99101
pandas_dataframe = pandas_dataframe.to_frame()
102+
100103
local_block = bigframes.core.blocks.Block.from_local(pandas_dataframe, self)
101104
bf_df = bigframes.dataframe.DataFrame(local_block)
102-
if isinstance(pandas_dataframe, pandas.Series):
105+
106+
if isinstance(original_input, pandas.Series):
103107
series = bf_df[bf_df.columns[0]]
104-
series.name = pandas_dataframe.name
108+
series.name = original_input.name
105109
return series
106-
if isinstance(pandas_dataframe, pandas.Index):
110+
111+
if isinstance(original_input, pandas.Index):
107112
return bf_df.index
113+
108114
return bf_df
109115

110116
@property

0 commit comments

Comments
 (0)