@@ -386,25 +386,25 @@ def test_to_pandas_batches_preserves_dtypes_for_populated_nested_json(session):
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-
390389 batches = list (df .to_pandas_batches ())
391390
392- # Check that we processed the row
393391 assert sum (len (b ) for b in batches ) == 1
394392
395- # Check dtypes on the resulting batch
396- assert isinstance (batches [0 ].dtypes ["json_array" ], pd .ArrowDtype )
397- assert isinstance (batches [0 ].dtypes ["json_array" ].pyarrow_dtype , pa .ListType )
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"
400+
401+ # Struct types work in both pandas versions
398402 assert isinstance (batches [0 ].dtypes ["json_struct" ], pd .ArrowDtype )
399403 assert isinstance (batches [0 ].dtypes ["json_struct" ].pyarrow_dtype , pa .StructType )
400404
401405
402406def test_to_pandas_batches_should_not_error_on_empty_nested_json (session ):
403- """Verify to_pandas_batches() works with empty nested JSON types.
404-
405- Regression test for PyArrow limitation with empty JSON arrays.
406- """
407- # This SQL query is MINIMAL and tests only the EMPTY regression case.
407+ """Verify to_pandas_batches() works with empty nested JSON types."""
408408 sql = """
409409 SELECT
410410 1 AS id,
@@ -413,14 +413,16 @@ def test_to_pandas_batches_should_not_error_on_empty_nested_json(session):
413413 """
414414 df = session .read_gbq (sql , index_col = "id" )
415415
416- # The main point of this test is that this line does not raise an error.
416+ # The main point: this should not raise an error
417417 batches = list (df .to_pandas_batches ())
418-
419- # Verify the row was actually processed and not just skipped
420418 assert sum (len (b ) for b in batches ) == 1
421419
422- # Verify dtypes are still correct, even with empty data
423- assert isinstance (batches [0 ].dtypes ["json_array" ], pd .ArrowDtype )
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"
425+
424426 assert isinstance (batches [0 ].dtypes ["json_struct" ], pd .ArrowDtype )
425427
426428
0 commit comments