Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit f49385a

Browse files
committed
handle unnamed series input
1 parent c82e553 commit f49385a

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

bigframes/series.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import bigframes.core.block_transforms as block_ops
5454
import bigframes.core.blocks as blocks
5555
import bigframes.core.expression as ex
56+
import bigframes.core.guid as guid
5657
import bigframes.core.indexers
5758
import bigframes.core.indexes as indexes
5859
import bigframes.core.ordering as order
@@ -1200,12 +1201,20 @@ def dot(self, other):
12001201
if len(other.columns.names) == 1:
12011202
# Process single level columns in other
12021203
# Let's leverage the DataFrame.dot
1203-
na_mask = other.isna().any()
1204-
self_as_row = self.to_frame().T
1204+
self_named = self
1205+
if self_named.name is None:
1206+
self_named = self.copy()
1207+
self_named.name = guid.generate_guid()
1208+
1209+
self_as_row = self_named.to_frame().T
12051210
frame_dot_result_as_row = self_as_row.dot(other)
12061211
frame_dot_result_as_col = frame_dot_result_as_row.T
1207-
series_dot_result = frame_dot_result_as_col[self.name]
1212+
series_dot_result = frame_dot_result_as_col[self_named.name]
1213+
1214+
# take care of the NA values
1215+
na_mask = other.isna().any()
12081216
result = series_dot_result.mask(na_mask)
1217+
result.name = self.name
12091218
else:
12101219
# TODO: Remove this special code path after DataFrame.dot supports
12111220
# multi-level columns.

tests/system/small/test_series.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3195,6 +3195,29 @@ def test_dot_df_with_na(scalars_dfs):
31953195
)
31963196

31973197

3198+
def test_dot_df_unnamed(session):
3199+
ps = pd.Series([0, 1, 2, 3])
3200+
assert ps.name is None # this is the scenario we are testing specifically
3201+
3202+
pdf = pd.DataFrame(
3203+
{"a": [-1, 2, -3, 4], "b": [-10, 20, -30, 40], "c": [-1, 2, -3, pd.NA]}
3204+
)
3205+
3206+
s = session.read_pandas(ps)
3207+
df = session.read_pandas(pdf)
3208+
3209+
pd_result = ps @ pdf
3210+
bf_result = s @ df
3211+
3212+
pd.testing.assert_series_equal(
3213+
bf_result.to_pandas(),
3214+
pd_result,
3215+
check_index_type=False,
3216+
check_dtype=False,
3217+
check_exact=False,
3218+
)
3219+
3220+
31983221
@pytest.mark.parametrize(
31993222
("left", "right", "inclusive"),
32003223
[

0 commit comments

Comments
 (0)