@@ -645,6 +645,92 @@ def test_to_dataframe_w_dtypes_arrow(class_under_test):
645645 )
646646
647647
648+ def test_to_dataframe_empty_w_scalars_avro (class_under_test ):
649+ avro_schema = _bq_to_avro_schema (SCALAR_COLUMNS )
650+ read_session = _generate_avro_read_session (avro_schema )
651+ avro_blocks = _bq_to_avro_blocks ([], avro_schema )
652+ reader = class_under_test (avro_blocks , mock_client , "" , 0 , {})
653+
654+ got = reader .to_dataframe (read_session )
655+
656+ expected = pandas .DataFrame (columns = SCALAR_COLUMN_NAMES )
657+ expected ["int_col" ] = expected ["int_col" ].astype ("int64" )
658+ expected ["float_col" ] = expected ["float_col" ].astype ("float64" )
659+ expected ["bool_col" ] = expected ["bool_col" ].astype ("bool" )
660+ expected ["ts_col" ] = expected ["ts_col" ].astype ("datetime64[ns, UTC]" )
661+
662+ pandas .testing .assert_frame_equal (
663+ got .reset_index (drop = True ), # reset_index to ignore row labels
664+ expected .reset_index (drop = True ),
665+ )
666+
667+
668+ def test_to_dataframe_empty_w_scalars_arrow (class_under_test ):
669+ arrow_schema = _bq_to_arrow_schema (SCALAR_COLUMNS )
670+ read_session = _generate_arrow_read_session (arrow_schema )
671+ arrow_batches = _bq_to_arrow_batches ([], arrow_schema )
672+ reader = class_under_test (arrow_batches , mock_client , "" , 0 , {})
673+
674+ got = reader .to_dataframe (read_session )
675+
676+ expected = pandas .DataFrame ([], columns = SCALAR_COLUMN_NAMES )
677+ expected ["int_col" ] = expected ["int_col" ].astype ("int64" )
678+ expected ["float_col" ] = expected ["float_col" ].astype ("float64" )
679+ expected ["bool_col" ] = expected ["bool_col" ].astype ("bool" )
680+ expected ["ts_col" ] = expected ["ts_col" ].astype ("datetime64[ns, UTC]" )
681+
682+ pandas .testing .assert_frame_equal (
683+ got .reset_index (drop = True ), # reset_index to ignore row labels
684+ expected .reset_index (drop = True ),
685+ )
686+
687+
688+ def test_to_dataframe_empty_w_dtypes_avro (class_under_test , mock_client ):
689+ avro_schema = _bq_to_avro_schema (
690+ [
691+ {"name" : "bigfloat" , "type" : "float64" },
692+ {"name" : "lilfloat" , "type" : "float64" },
693+ ]
694+ )
695+ read_session = _generate_avro_read_session (avro_schema )
696+ avro_blocks = _bq_to_avro_blocks ([], avro_schema )
697+ reader = class_under_test (avro_blocks , mock_client , "" , 0 , {})
698+
699+ got = reader .to_dataframe (read_session , dtypes = {"lilfloat" : "float16" })
700+
701+ expected = pandas .DataFrame ([], columns = ["bigfloat" , "lilfloat" ])
702+ expected ["bigfloat" ] = expected ["bigfloat" ].astype ("float64" )
703+ expected ["lilfloat" ] = expected ["lilfloat" ].astype ("float16" )
704+
705+ pandas .testing .assert_frame_equal (
706+ got .reset_index (drop = True ), # reset_index to ignore row labels
707+ expected .reset_index (drop = True ),
708+ )
709+
710+
711+ def test_to_dataframe_empty_w_dtypes_arrow (class_under_test , mock_client ):
712+ arrow_schema = _bq_to_arrow_schema (
713+ [
714+ {"name" : "bigfloat" , "type" : "float64" },
715+ {"name" : "lilfloat" , "type" : "float64" },
716+ ]
717+ )
718+ read_session = _generate_arrow_read_session (arrow_schema )
719+ arrow_batches = _bq_to_arrow_batches ([], arrow_schema )
720+ reader = class_under_test (arrow_batches , mock_client , "" , 0 , {})
721+
722+ got = reader .to_dataframe (read_session , dtypes = {"lilfloat" : "float16" })
723+
724+ expected = pandas .DataFrame ([], columns = ["bigfloat" , "lilfloat" ])
725+ expected ["bigfloat" ] = expected ["bigfloat" ].astype ("float64" )
726+ expected ["lilfloat" ] = expected ["lilfloat" ].astype ("float16" )
727+
728+ pandas .testing .assert_frame_equal (
729+ got .reset_index (drop = True ), # reset_index to ignore row labels
730+ expected .reset_index (drop = True ),
731+ )
732+
733+
648734def test_to_dataframe_by_page (class_under_test , mock_client ):
649735 bq_columns = [
650736 {"name" : "int_col" , "type" : "int64" },
0 commit comments