Skip to content

Commit 080eb7b

Browse files
fix: Fix single row broadcast with null index (#1803)
1 parent e0f065f commit 080eb7b

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

bigframes/core/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,7 @@ def join_with_single_row(
28952895
combined_expr,
28962896
index_columns=index_cols_post_join,
28972897
column_labels=left.column_labels.append(single_row_block.column_labels),
2898-
index_labels=[left.index.name],
2898+
index_labels=left.index.names,
28992899
)
29002900
return (
29012901
block,

tests/system/small/test_dataframe.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,16 +2657,16 @@ def test_listlike_binop_axis_1_bf_index(scalars_dfs):
26572657
assert_pandas_df_equal(bf_result, pd_result, check_dtype=False)
26582658

26592659

2660-
def test_binop_with_self_aggregate(session, scalars_dfs):
2661-
scalars_df, scalars_pandas_df = scalars_dfs
2660+
def test_binop_with_self_aggregate(scalars_dfs_maybe_ordered):
2661+
scalars_df, scalars_pandas_df = scalars_dfs_maybe_ordered
26622662

26632663
df_columns = ["int64_col", "float64_col", "int64_too"]
26642664

26652665
# Ensure that this takes the optimized single-query path by counting executions
2666-
execution_count_before = session._metrics.execution_count
2666+
execution_count_before = scalars_df._session._metrics.execution_count
26672667
bf_df = scalars_df[df_columns]
26682668
bf_result = (bf_df - bf_df.mean()).to_pandas()
2669-
execution_count_after = session._metrics.execution_count
2669+
execution_count_after = scalars_df._session._metrics.execution_count
26702670

26712671
pd_df = scalars_pandas_df[df_columns]
26722672
pd_result = pd_df - pd_df.mean()
@@ -2677,6 +2677,29 @@ def test_binop_with_self_aggregate(session, scalars_dfs):
26772677
assert_pandas_df_equal(bf_result, pd_result, check_dtype=False)
26782678

26792679

2680+
def test_binop_with_self_aggregate_w_index_reset(scalars_dfs_maybe_ordered):
2681+
scalars_df, scalars_pandas_df = scalars_dfs_maybe_ordered
2682+
2683+
df_columns = ["int64_col", "float64_col", "int64_too"]
2684+
2685+
# Ensure that this takes the optimized single-query path by counting executions
2686+
execution_count_before = scalars_df._session._metrics.execution_count
2687+
bf_df = scalars_df[df_columns].reset_index(drop=True)
2688+
bf_result = (bf_df - bf_df.mean()).to_pandas()
2689+
execution_count_after = scalars_df._session._metrics.execution_count
2690+
2691+
pd_df = scalars_pandas_df[df_columns].reset_index(drop=True)
2692+
pd_result = pd_df - pd_df.mean()
2693+
2694+
executions = execution_count_after - execution_count_before
2695+
2696+
assert executions == 1
2697+
pd_result.index = pd_result.index.astype("Int64")
2698+
assert_pandas_df_equal(
2699+
bf_result, pd_result, check_dtype=False, check_index_type=False
2700+
)
2701+
2702+
26802703
@pytest.mark.parametrize(
26812704
("left_labels", "right_labels"),
26822705
[

0 commit comments

Comments
 (0)