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

Commit 2d1c6d4

Browse files
committed
test: add dedicated test for empty struct array unnest schema
1 parent a874f6f commit 2d1c6d4

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

tests/system/small/test_multiindex.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,28 +1490,3 @@ def test_multiindex_eq_const(scalars_df_index, scalars_pandas_df_index):
14901490
bigframes.testing.utils.assert_index_equal(
14911491
pandas.Index(pd_result, dtype="boolean"), bf_result.to_pandas()
14921492
)
1493-
1494-
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().to_pandas()
1503-
assert count_df.shape == (0,)
1504-
assert count_df.index.nlevels == 2
1505-
assert list(count_df.index.names) == ["a", "b"]
1506-
1507-
1508-
def test_count_preserves_multiindex_columns(session):
1509-
# Tests that `melt` operations via count do not cause MultiIndex drops in Arrow
1510-
df = pandas.DataFrame({"A": [1], "B": ["string"], "C": [3]})
1511-
df.columns = pandas.MultiIndex.from_tuples(
1512-
[("Group1", "A"), ("Group2", "B"), ("Group1", "C")]
1513-
)
1514-
bdf = session.read_pandas(df)
1515-
1516-
count_df = bdf.count().to_pandas()
1517-
assert count_df.shape[0] == 3

tests/unit/core/compile/sqlglot/test_compile_readlocal.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414

1515
import numpy as np
1616
import pandas as pd
17+
import pyarrow as pa
1718
import pytest
1819

1920
import bigframes
21+
from bigframes.core import schema
22+
from bigframes.core.compile.sqlglot.sqlglot_ir import SQLGlotIR
23+
from bigframes.core.guid import SequentialUIDGenerator
2024
import bigframes.pandas as bpd
2125

2226
pytest.importorskip("pytest_snapshot")
@@ -76,3 +80,12 @@ def test_compile_readlocal_w_special_values(
7680
)
7781
bf_df = bpd.DataFrame(df, session=compiler_session)
7882
snapshot.assert_match(bf_df.sql, "out.sql")
83+
84+
85+
def test_compile_from_pyarrow_empty_schema():
86+
pa_table = pa.Table.from_arrays([], names=[])
87+
schema_obj = schema.ArraySchema(items=())
88+
uid_gen = SequentialUIDGenerator()
89+
ir = SQLGlotIR.from_pyarrow(pa_table, schema_obj, uid_gen)
90+
sql_str = ir.sql
91+
assert "__empty_struct_dummy__" in sql_str

0 commit comments

Comments
 (0)