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

Commit 3119771

Browse files
committed
testcase update
1 parent 5f5881b commit 3119771

1 file changed

Lines changed: 17 additions & 23 deletions

File tree

tests/system/small/test_dataframe_io.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -378,33 +378,29 @@ def test_to_pandas_batches_w_empty_dataframe(session):
378378

379379
def test_to_pandas_batches_preserves_dtypes_for_populated_nested_json(session):
380380
"""Verifies to_pandas_batches() preserves dtypes for nested JSON."""
381-
# This SQL query only tests the POPULATED case.
381+
382382
sql = """
383383
SELECT
384384
0 AS id,
385385
[JSON '{"a":1}', JSON '{"b":2}'] AS json_array,
386386
STRUCT(JSON '{"x":1}' AS json_field, 'test' AS str_field) AS json_struct
387387
"""
388388
df = session.read_gbq(sql, index_col="id")
389-
batches = list(df.to_pandas_batches())
390-
391-
assert sum(len(b) for b in batches) == 1
392389

393-
# Check dtypes based on pandas version
394-
if bigframes.features.PANDAS_VERSIONS.is_arrow_list_dtype_usable:
395-
assert isinstance(batches[0].dtypes["json_array"], pd.ArrowDtype)
396-
assert isinstance(batches[0].dtypes["json_array"].pyarrow_dtype, pa.ListType)
397-
else:
398-
# In pandas 1.x, list types become object dtype
399-
assert batches[0].dtypes["json_array"] == "object"
390+
batches = list(df.to_pandas_batches())
400391

401-
# Struct types work in both pandas versions
402-
assert isinstance(batches[0].dtypes["json_struct"], pd.ArrowDtype)
403-
assert isinstance(batches[0].dtypes["json_struct"].pyarrow_dtype, pa.StructType)
392+
# Focuses only on the "preserves dtypes" behavior.
393+
# This implicitly checks that at least one batch was produced.
394+
pd.testing.assert_series_equal(
395+
batches[0].dtypes,
396+
df.dtypes,
397+
check_dtype=bigframes.features.PANDAS_VERSIONS.is_arrow_list_dtype_usable,
398+
)
404399

405400

406401
def test_to_pandas_batches_should_not_error_on_empty_nested_json(session):
407402
"""Verify to_pandas_batches() works with empty nested JSON types."""
403+
408404
sql = """
409405
SELECT
410406
1 AS id,
@@ -413,17 +409,15 @@ def test_to_pandas_batches_should_not_error_on_empty_nested_json(session):
413409
"""
414410
df = session.read_gbq(sql, index_col="id")
415411

416-
# The main point: this should not raise an error
412+
# Verify that this line does not raise an error.
417413
batches = list(df.to_pandas_batches())
418-
assert sum(len(b) for b in batches) == 1
419-
420-
# Check dtypes based on pandas version
421-
if bigframes.features.PANDAS_VERSIONS.is_arrow_list_dtype_usable:
422-
assert isinstance(batches[0].dtypes["json_array"], pd.ArrowDtype)
423-
else:
424-
assert batches[0].dtypes["json_array"] == "object"
425414

426-
assert isinstance(batches[0].dtypes["json_struct"], pd.ArrowDtype)
415+
# Verify the resulting dtypes are correct for the empty/null data
416+
pd.testing.assert_series_equal(
417+
batches[0].dtypes,
418+
df.dtypes,
419+
check_dtype=bigframes.features.PANDAS_VERSIONS.is_arrow_list_dtype_usable,
420+
)
427421

428422

429423
@pytest.mark.parametrize("allow_large_results", (True, False))

0 commit comments

Comments
 (0)