@@ -450,6 +450,72 @@ def test_merge_raises_error_when_left_right_on_set(scalars_dfs):
450450 )
451451
452452
453+ def test_crosstab_aligned_series (scalars_dfs ):
454+ scalars_df , scalars_pandas_df = scalars_dfs
455+
456+ pd_result = pd .crosstab (
457+ scalars_pandas_df ["int64_col" ], scalars_pandas_df ["int64_too" ]
458+ )
459+ bf_result = bpd .crosstab (
460+ scalars_df ["int64_col" ], scalars_df ["int64_too" ]
461+ ).to_pandas ()
462+
463+ assert_pandas_df_equal (bf_result , pd_result , check_dtype = False )
464+
465+
466+ def test_crosstab_nondefault_func (scalars_dfs ):
467+ scalars_df , scalars_pandas_df = scalars_dfs
468+
469+ pd_result = pd .crosstab (
470+ scalars_pandas_df ["int64_col" ],
471+ scalars_pandas_df ["int64_too" ],
472+ values = scalars_pandas_df ["float64_col" ],
473+ aggfunc = "mean" ,
474+ )
475+ bf_result = bpd .crosstab (
476+ scalars_df ["int64_col" ],
477+ scalars_df ["int64_too" ],
478+ values = scalars_df ["float64_col" ],
479+ aggfunc = "mean" ,
480+ ).to_pandas ()
481+
482+ assert_pandas_df_equal (bf_result , pd_result , check_dtype = False )
483+
484+
485+ def test_crosstab_multi_cols (scalars_dfs ):
486+ scalars_df , scalars_pandas_df = scalars_dfs
487+
488+ pd_result = pd .crosstab (
489+ [scalars_pandas_df ["int64_col" ], scalars_pandas_df ["bool_col" ]],
490+ [scalars_pandas_df ["int64_too" ], scalars_pandas_df ["string_col" ]],
491+ rownames = ["a" , "b" ],
492+ colnames = ["c" , "d" ],
493+ )
494+ bf_result = bpd .crosstab (
495+ [scalars_df ["int64_col" ], scalars_df ["bool_col" ]],
496+ [scalars_df ["int64_too" ], scalars_df ["string_col" ]],
497+ rownames = ["a" , "b" ],
498+ colnames = ["c" , "d" ],
499+ ).to_pandas ()
500+
501+ assert_pandas_df_equal (bf_result , pd_result , check_dtype = False )
502+
503+
504+ def test_crosstab_unaligned_series (scalars_dfs , session ):
505+ scalars_df , scalars_pandas_df = scalars_dfs
506+ other_pd_series = pd .Series (
507+ [10 , 20 , 10 , 30 , 10 ], index = [5 , 4 , 1 , 2 , 3 ], dtype = "Int64" , name = "nums"
508+ )
509+ other_bf_series = session .Series (
510+ [10 , 20 , 10 , 30 , 10 ], index = [5 , 4 , 1 , 2 , 3 ], name = "nums"
511+ )
512+
513+ pd_result = pd .crosstab (scalars_pandas_df ["int64_col" ], other_pd_series )
514+ bf_result = bpd .crosstab (scalars_df ["int64_col" ], other_bf_series ).to_pandas ()
515+
516+ assert_pandas_df_equal (bf_result , pd_result , check_dtype = False )
517+
518+
453519def _convert_pandas_category (pd_s : pd .Series ):
454520 """
455521 Transforms a pandas Series with Categorical dtype into a bigframes-compatible
0 commit comments