@@ -575,7 +575,15 @@ def test_series_int_int_operators_series(scalars_dfs, operator):
575
575
)
576
576
def test_mods (scalars_dfs , col_x , col_y , method ):
577
577
scalars_df , scalars_pandas_df = scalars_dfs
578
- bf_result = getattr (scalars_df [col_x ], method )(scalars_df [col_y ]).to_pandas ()
578
+ x_bf = scalars_df [col_x ]
579
+ y_bf = scalars_df [col_y ]
580
+ bf_series = getattr (x_bf , method )(y_bf )
581
+ # BigQuery's mod functions return [BIG]NUMERIC values unless both arguments are integers.
582
+ # https://cloud.google.com/bigquery/docs/reference/standard-sql/mathematical_functions#mod
583
+ if x_bf .dtype == pd .Int64Dtype () and y_bf .dtype == pd .Int64Dtype ():
584
+ bf_result = bf_series .to_pandas ()
585
+ else :
586
+ bf_result = bf_series .astype ("Float64" ).to_pandas ()
579
587
pd_result = getattr (scalars_pandas_df [col_x ], method )(scalars_pandas_df [col_y ])
580
588
pd .testing .assert_series_equal (pd_result , bf_result )
581
589
@@ -620,8 +628,20 @@ def test_divmods_series(scalars_dfs, col_x, col_y, method):
620
628
pd_div_result , pd_mod_result = getattr (scalars_pandas_df [col_x ], method )(
621
629
scalars_pandas_df [col_y ]
622
630
)
623
- pd .testing .assert_series_equal (pd_div_result , bf_div_result .to_pandas ())
624
- pd .testing .assert_series_equal (pd_mod_result , bf_mod_result .to_pandas ())
631
+ # BigQuery's mod functions return NUMERIC values for non-INT64 inputs.
632
+ if bf_div_result .dtype == pd .Int64Dtype ():
633
+ pd .testing .assert_series_equal (pd_div_result , bf_div_result .to_pandas ())
634
+ else :
635
+ pd .testing .assert_series_equal (
636
+ pd_div_result , bf_div_result .astype ("Float64" ).to_pandas ()
637
+ )
638
+
639
+ if bf_mod_result .dtype == pd .Int64Dtype ():
640
+ pd .testing .assert_series_equal (pd_mod_result , bf_mod_result .to_pandas ())
641
+ else :
642
+ pd .testing .assert_series_equal (
643
+ pd_mod_result , bf_mod_result .astype ("Float64" ).to_pandas ()
644
+ )
625
645
626
646
627
647
@pytest .mark .parametrize (
@@ -649,8 +669,20 @@ def test_divmods_scalars(scalars_dfs, col_x, other, method):
649
669
scalars_df , scalars_pandas_df = scalars_dfs
650
670
bf_div_result , bf_mod_result = getattr (scalars_df [col_x ], method )(other )
651
671
pd_div_result , pd_mod_result = getattr (scalars_pandas_df [col_x ], method )(other )
652
- pd .testing .assert_series_equal (pd_div_result , bf_div_result .to_pandas ())
653
- pd .testing .assert_series_equal (pd_mod_result , bf_mod_result .to_pandas ())
672
+ # BigQuery's mod functions return NUMERIC values for non-INT64 inputs.
673
+ if bf_div_result .dtype == pd .Int64Dtype ():
674
+ pd .testing .assert_series_equal (pd_div_result , bf_div_result .to_pandas ())
675
+ else :
676
+ pd .testing .assert_series_equal (
677
+ pd_div_result , bf_div_result .astype ("Float64" ).to_pandas ()
678
+ )
679
+
680
+ if bf_mod_result .dtype == pd .Int64Dtype ():
681
+ pd .testing .assert_series_equal (pd_mod_result , bf_mod_result .to_pandas ())
682
+ else :
683
+ pd .testing .assert_series_equal (
684
+ pd_mod_result , bf_mod_result .astype ("Float64" ).to_pandas ()
685
+ )
654
686
655
687
656
688
@pytest .mark .parametrize (
@@ -1941,12 +1973,6 @@ def test_iloc_nested(scalars_df_index, scalars_pandas_df_index):
1941
1973
def test_series_iloc (scalars_df_index , scalars_pandas_df_index , start , stop , step ):
1942
1974
bf_result = scalars_df_index ["string_col" ].iloc [start :stop :step ].to_pandas ()
1943
1975
pd_result = scalars_pandas_df_index ["string_col" ].iloc [start :stop :step ]
1944
-
1945
- # Pandas may assign non-object dtype to empty series and series index
1946
- if pd_result .empty :
1947
- pd_result = pd_result .astype ("object" )
1948
- pd_result .index = pd_result .index .astype ("object" )
1949
-
1950
1976
pd .testing .assert_series_equal (
1951
1977
bf_result ,
1952
1978
pd_result ,
0 commit comments