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

Commit 156603c

Browse files
committed
test: add test case for empty multiindex unpivot bypassing struct compiler bugs
1 parent 7682f7d commit 156603c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/system/small/test_multiindex.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,25 @@ def test_multiindex_eq_const(scalars_df_index, scalars_pandas_df_index):
14921492
)
14931493

14941494

1495+
def test_count_empty_multiindex_columns(session):
1496+
df = pandas.DataFrame(
1497+
[], index=[1, 2], columns=pandas.MultiIndex.from_tuples([], names=["a", "b"])
1498+
)
1499+
bdf = session.read_pandas(df)
1500+
1501+
# count() operation unpivots columns, triggering the empty MultiIndex bug internally
1502+
count_df = bdf.count()
1503+
1504+
# The local fix ensures that empty unpivoted columns generate properly typed NULLs
1505+
# rather than failing syntax validation downstream in BigQuery.
1506+
# We compile to `.sql` to verify it succeeds locally without evaluating on BigQuery natively.
1507+
_ = count_df.to_frame().sql
1508+
1509+
# Assert structural layout is correct
1510+
assert count_df.index.nlevels == 2
1511+
assert list(count_df.index.names) == ["a", "b"]
1512+
1513+
14951514
def test_dataframe_melt_multiindex(session):
14961515
# Tests that `melt` operations via count do not cause MultiIndex drops in Arrow
14971516
df = pandas.DataFrame({"A": [1], "B": ["string"], "C": [3]})

0 commit comments

Comments
 (0)