@@ -15,6 +15,10 @@ class BaseReduceTests(BaseExtensionTests):
1515 make sense for numeric/boolean operations.
1616 """
1717
18+ def _supports_reduction (self , obj , op_name : str ) -> bool :
19+ # Specify if we expect this reduction to succeed.
20+ return False
21+
1822 def check_reduce (self , s , op_name , skipna ):
1923 # We perform the same operation on the np.float64 data and check
2024 # that the results match. Override if you need to cast to something
@@ -66,47 +70,42 @@ def check_reduce_frame(self, ser: pd.Series, op_name: str, skipna: bool):
6670
6771 tm .assert_extension_array_equal (result1 , expected )
6872
69-
70- class BaseNoReduceTests (BaseReduceTests ):
71- """we don't define any reductions"""
72-
73- @pytest .mark .parametrize ("skipna" , [True , False ])
74- def test_reduce_series_numeric (self , data , all_numeric_reductions , skipna ):
75- op_name = all_numeric_reductions
76- s = pd .Series (data )
77-
78- msg = (
79- "[Cc]annot perform|Categorical is not ordered for operation|"
80- "does not support reduction|"
81- )
82-
83- with pytest .raises (TypeError , match = msg ):
84- getattr (s , op_name )(skipna = skipna )
85-
8673 @pytest .mark .parametrize ("skipna" , [True , False ])
8774 def test_reduce_series_boolean (self , data , all_boolean_reductions , skipna ):
8875 op_name = all_boolean_reductions
8976 s = pd .Series (data )
9077
91- msg = (
92- "[Cc]annot perform|Categorical is not ordered for operation|"
93- "does not support reduction|"
94- )
78+ if not self ._supports_reduction (s , op_name ):
79+ msg = (
80+ "[Cc]annot perform|Categorical is not ordered for operation|"
81+ "does not support reduction|"
82+ )
9583
96- with pytest .raises (TypeError , match = msg ):
97- getattr (s , op_name )(skipna = skipna )
84+ with pytest .raises (TypeError , match = msg ):
85+ getattr (s , op_name )(skipna = skipna )
9886
87+ else :
88+ self .check_reduce (s , op_name , skipna )
9989
100- class BaseNumericReduceTests (BaseReduceTests ):
10190 @pytest .mark .parametrize ("skipna" , [True , False ])
102- def test_reduce_series (self , data , all_numeric_reductions , skipna ):
91+ def test_reduce_series_numeric (self , data , all_numeric_reductions , skipna ):
10392 op_name = all_numeric_reductions
10493 s = pd .Series (data )
10594
106- # min/max with empty produce numpy warnings
107- with warnings .catch_warnings ():
108- warnings .simplefilter ("ignore" , RuntimeWarning )
109- self .check_reduce (s , op_name , skipna )
95+ if not self ._supports_reduction (s , op_name ):
96+ msg = (
97+ "[Cc]annot perform|Categorical is not ordered for operation|"
98+ "does not support reduction|"
99+ )
100+
101+ with pytest .raises (TypeError , match = msg ):
102+ getattr (s , op_name )(skipna = skipna )
103+
104+ else :
105+ # min/max with empty produce numpy warnings
106+ with warnings .catch_warnings ():
107+ warnings .simplefilter ("ignore" , RuntimeWarning )
108+ self .check_reduce (s , op_name , skipna )
110109
111110 @pytest .mark .parametrize ("skipna" , [True , False ])
112111 def test_reduce_frame (self , data , all_numeric_reductions , skipna ):
@@ -118,12 +117,28 @@ def test_reduce_frame(self, data, all_numeric_reductions, skipna):
118117 if op_name in ["count" , "kurt" , "sem" ]:
119118 pytest .skip (f"{ op_name } not an array method" )
120119
120+ if not self ._supports_reduction (s , op_name ):
121+ pytest .skip (f"Reduction { op_name } not supported for this dtype" )
122+
121123 self .check_reduce_frame (s , op_name , skipna )
122124
123125
126+ # TODO: deprecate BaseNoReduceTests, BaseNumericReduceTests, BaseBooleanReduceTests
127+ class BaseNoReduceTests (BaseReduceTests ):
128+ """we don't define any reductions"""
129+
130+
131+ class BaseNumericReduceTests (BaseReduceTests ):
132+ # For backward compatibility only, this only runs the numeric reductions
133+ def _supports_reduction (self , obj , op_name : str ) -> bool :
134+ if op_name in ["any" , "all" ]:
135+ pytest .skip ("These are tested in BaseBooleanReduceTests" )
136+ return True
137+
138+
124139class BaseBooleanReduceTests (BaseReduceTests ):
125- @ pytest . mark . parametrize ( "skipna" , [ True , False ])
126- def test_reduce_series (self , data , all_boolean_reductions , skipna ) :
127- op_name = all_boolean_reductions
128- s = pd . Series ( data )
129- self . check_reduce ( s , op_name , skipna )
140+ # For backward compatibility only, this only runs the numeric reductions
141+ def _supports_reduction (self , obj , op_name : str ) -> bool :
142+ if op_name not in [ "any" , "all" ]:
143+ pytest . skip ( "These are tested in BaseNumericReduceTests" )
144+ return True
0 commit comments