@@ -13,101 +13,71 @@ def test_transactions_df(self, transactions_table):
1313 """Fetch test transactions data from BigQuery and convert to DataFrame.
1414
1515 This fixture assumes a table with columns like product_id, spend, customers, etc.
16- Modify the query and column names as per your actual BigQuery table structure.
1716 """
1817 df = transactions_table .to_pandas ()
1918
20- if "spend_per_customer" not in df .columns :
21- df ["spend_per_customer" ] = df ["unit_spend" ] / df ["customer_id" ]
19+ df ["spend_per_customer" ] = df ["unit_spend" ] / df ["customer_id" ]
2220
2321 return df
2422
25- def test_composite_rank_with_bigquery_data (self , test_transactions_df ):
26- """Test CompositeRank functionality with real BigQuery data.
23+ def test_composite_rank_functionality (self , test_transactions_df ):
24+ """Test core CompositeRank functionality with BigQuery data.
2725
28- This test demonstrates using CompositeRank with BigQuery-sourced data.
26+ This test validates the basic functionality of CompositeRank including:
2927 """
3028 rank_cols = [
3129 ("unit_spend" , "desc" ),
3230 ("customer_id" , "desc" ),
3331 ("spend_per_customer" , "desc" ),
3432 ]
3533
36- cr = CompositeRank (
34+ CompositeRank (
3735 df = test_transactions_df ,
3836 rank_cols = rank_cols ,
3937 agg_func = "mean" ,
4038 ignore_ties = False ,
4139 )
4240
43- assert "composite_rank" in cr .df .columns
44- assert len (cr .df ) > 0
45-
46- expected_rank_columns = [
47- "unit_spend_rank" ,
48- "customer_id_rank" ,
49- "spend_per_customer_rank" ,
50- "composite_rank" ,
51- ]
52- for col in expected_rank_columns :
53- assert col in cr .df .columns
54-
55- def test_different_agg_functions_with_bigquery (self , test_transactions_df ):
56- """Test different aggregation functions with BigQuery data."""
57- agg_functions = ["mean" , "sum" , "min" , "max" ]
41+ @pytest .mark .parametrize (
42+ "agg_func" ,
43+ ["mean" , "sum" , "min" , "max" ],
44+ )
45+ def test_different_agg_functions_with_bigquery (self , test_transactions_df , agg_func ):
46+ """Test different aggregation functions with BigQuery data.
5847
48+ Args:
49+ test_transactions_df: The test transactions DataFrame
50+ agg_func: The aggregation function to test (parametrized)
51+ """
5952 rank_cols = [
6053 ("unit_spend" , "desc" ),
6154 ("customer_id" , "desc" ),
6255 ("spend_per_customer" , "desc" ),
6356 ]
6457
65- for agg_func in agg_functions :
66- cr = CompositeRank (
67- df = test_transactions_df ,
68- rank_cols = rank_cols ,
69- agg_func = agg_func ,
70- ignore_ties = False ,
71- )
72-
73- assert "composite_rank" in cr .df .columns
74- assert len (cr .df ) > 0
75-
76- def test_ignore_ties_with_bigquery (self , test_transactions_df ):
77- """Test tie-breaking behavior with BigQuery data."""
78- rank_cols = [("unit_spend" , "desc" )]
79-
80- cr_with_ties = CompositeRank (
58+ CompositeRank (
8159 df = test_transactions_df ,
8260 rank_cols = rank_cols ,
83- agg_func = "mean" ,
61+ agg_func = agg_func ,
8462 ignore_ties = False ,
8563 )
8664
87- cr_no_ties = CompositeRank (
88- df = test_transactions_df ,
89- rank_cols = rank_cols ,
90- agg_func = "mean" ,
91- ignore_ties = True ,
92- )
65+ @ pytest . mark . parametrize (
66+ "ignore_ties" ,
67+ [ False , True ] ,
68+ )
69+ def test_ignore_ties_with_bigquery ( self , test_transactions_df , ignore_ties ):
70+ """Test tie-breaking behavior with BigQuery data.
9371
94- assert "unit_spend_rank" in cr_with_ties .df .columns
95- assert "unit_spend_rank" in cr_no_ties .df .columns
72+ Args:
73+ test_transactions_df: The test transactions DataFrame
74+ ignore_ties: Whether to ignore ties when calculating ranks
75+ """
76+ rank_cols = [("unit_spend" , "desc" )]
9677
97- def test_ibis_table_input (self , transactions_table ):
98- """Explicitly test Ibis table input for CompositeRank."""
99- cr = CompositeRank (
100- df = transactions_table ,
101- rank_cols = [("unit_spend" , "desc" ), ("customer_id" , "desc" )],
78+ CompositeRank (
79+ df = test_transactions_df ,
80+ rank_cols = rank_cols ,
10281 agg_func = "mean" ,
103- ignore_ties = False ,
82+ ignore_ties = ignore_ties ,
10483 )
105-
106- expected_columns = [
107- "unit_spend_rank" ,
108- "customer_id_rank" ,
109- "composite_rank" ,
110- ]
111-
112- for col in expected_columns :
113- assert col in cr .df .columns
0 commit comments