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