@@ -997,8 +997,9 @@ def test_decimate_same_y(self):
997997 pd .testing .assert_series_equal (data ["x" ], output ["x" ])
998998 pd .testing .assert_series_equal (data ["y" ], output ["y" ])
999999
1000+
1001+ class TestCategoricalAgg :
10001002 def test_categorical_agg_count (self ):
1001- """Default aggregation counts rows per category."""
10021003 df = pd .DataFrame (
10031004 {
10041005 "x" : [1 , 2 , 3 , 4 , 5 ],
@@ -1020,13 +1021,8 @@ def test_categorical_agg_count(self):
10201021 assert data ["B" ] == 2
10211022
10221023 def test_categorical_agg_sum (self ):
1023- """Sum aggregation on a value dimension."""
10241024 df = pd .DataFrame (
1025- {
1026- "x" : [1 , 2 , 3 , 4 ],
1027- "y" : [10 , 20 , 30 , 40 ],
1028- "category" : ["A" , "B" , "A" , "B" ],
1029- }
1025+ {"x" : [1 , 2 , 3 , 4 ], "y" : [10 , 20 , 30 , 40 ], "category" : ["A" , "B" , "A" , "B" ]}
10301026 )
10311027 points = hv .Points (df , kdims = ["x" , "y" ], vdims = ["category" ])
10321028 bars = categorical_agg (
@@ -1045,13 +1041,8 @@ def test_categorical_agg_sum(self):
10451041 assert data ["B" ] == 60 # 20 + 40
10461042
10471043 def test_categorical_agg_mean (self ):
1048- """Mean aggregation on a value dimension."""
10491044 df = pd .DataFrame (
1050- {
1051- "x" : [1 , 2 , 3 , 4 ],
1052- "y" : [10 , 20 , 30 , 40 ],
1053- "category" : ["A" , "B" , "A" , "B" ],
1054- }
1045+ {"x" : [1 , 2 , 3 , 4 ], "y" : [10 , 20 , 30 , 40 ], "category" : ["A" , "B" , "A" , "B" ]}
10551046 )
10561047 points = hv .Points (df , kdims = ["x" , "y" ], vdims = ["category" ])
10571048 bars = categorical_agg (points , dimension = "category" , value_dimension = "y" , function = np .mean )
@@ -1065,33 +1056,23 @@ def test_categorical_agg_mean(self):
10651056 assert data ["B" ] == 30.0 # (20 + 40) / 2
10661057
10671058 def test_categorical_agg_custom_label (self ):
1068- """Custom label overrides auto-generated label."""
1069- df = pd .DataFrame (
1070- {
1071- "x" : [1 , 2 , 3 ],
1072- "y" : [10 , 20 , 30 ],
1073- "category" : ["A" , "B" , "A" ],
1074- }
1075- )
1059+ df = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ], "category" : ["A" , "B" , "A" ]})
10761060 points = hv .Points (df , kdims = ["x" , "y" ], vdims = ["category" ])
10771061 bars = categorical_agg (points , dimension = "category" , label = "Total" )
10781062
10791063 assert bars .vdims [0 ].name == "Total"
10801064
10811065 def test_categorical_agg_missing_dimension_error (self ):
1082- """Raises ValueError when the specified dimension doesn't exist."""
10831066 points = hv .Points ([(1 , 2 ), (3 , 4 )])
10841067 with pytest .raises (ValueError , match = "not found" ):
10851068 categorical_agg (points , dimension = "nonexistent" )
10861069
10871070 def test_categorical_agg_no_dimension_error (self ):
1088- """Raises ValueError when dimension param is not provided."""
10891071 points = hv .Points ([(1 , 2 ), (3 , 4 )])
10901072 with pytest .raises (ValueError , match = "required" ):
10911073 categorical_agg (points )
10921074
10931075 def test_categorical_agg_empty_element (self ):
1094- """Returns an empty Bars element when the input is empty."""
10951076 df = pd .DataFrame ({"x" : [], "y" : [], "category" : []})
10961077 points = hv .Points (df , kdims = ["x" , "y" ], vdims = ["category" ])
10971078 bars = categorical_agg (points , dimension = "category" )
@@ -1100,14 +1081,7 @@ def test_categorical_agg_empty_element(self):
11001081 assert len (bars ) == 0
11011082
11021083 def test_categorical_agg_preserves_lineage (self ):
1103- """Operation output has a pipeline that references the source element."""
1104- df = pd .DataFrame (
1105- {
1106- "x" : [1 , 2 , 3 ],
1107- "y" : [10 , 20 , 30 ],
1108- "category" : ["A" , "B" , "A" ],
1109- }
1110- )
1084+ df = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ], "category" : ["A" , "B" , "A" ]})
11111085 points = hv .Points (df , kdims = ["x" , "y" ], vdims = ["category" ])
11121086 bars = categorical_agg (points , dimension = "category" )
11131087
0 commit comments