Skip to content

Commit f4b3afd

Browse files
committed
Fix: Handle empty index in unpivot with identity mapping
1 parent 7ad3a04 commit f4b3afd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

bigframes/core/blocks.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3435,7 +3435,12 @@ def unpivot(
34353435
# Last column is offsets
34363436
if not labels_array.column_ids:
34373437
# Handle empty column_ids case for multimodal DataFrames
3438-
return array_value, (tuple(), tuple(), tuple(passthrough_columns))
3438+
# When no index columns exist, return original array_value with identity mappings
3439+
return array_value, (
3440+
tuple(),
3441+
tuple(array_value.column_ids),
3442+
tuple(passthrough_columns),
3443+
)
34393444
index_col_ids = [labels_mapping[col] for col in labels_array.column_ids[:-1]]
34403445
explode_offsets_id = labels_mapping[labels_array.column_ids[-1]]
34413446

tests/unit/core/test_blocks_unpivot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ def test_unpivot_with_empty_row_labels(mock_session):
6363
array_value = blocks.core.ArrayValue.from_pyarrow(pa_table, session=mock_session)
6464

6565
# Call unpivot with an empty pd.Index
66-
unpivot_result, (index_cols, unpivot_cols, passthrough_cols) = blocks.unpivot(
66+
unpivot_result, (index_cols, value_cols, passthrough_cols) = blocks.unpivot(
6767
array_value,
6868
row_labels=pd.Index([]),
6969
unpivot_columns=[("a",)],
7070
)
7171

7272
# The expected behavior is that the unpivot operation does nothing and returns
73-
# the original array_value and empty column tuples.
73+
# the original array_value and identity mappings.
7474
assert unpivot_result is array_value
7575
assert index_cols == tuple()
76-
assert unpivot_cols == tuple()
76+
assert value_cols == tuple(array_value.column_ids)
7777
assert passthrough_cols == tuple()

0 commit comments

Comments
 (0)