@@ -15,6 +15,10 @@ class BaseReduceTests(BaseExtensionTests):
15
15
make sense for numeric/boolean operations.
16
16
"""
17
17
18
+ def _supports_reduction (self , obj , op_name : str ) -> bool :
19
+ # Specify if we expect this reduction to succeed.
20
+ return False
21
+
18
22
def check_reduce (self , s , op_name , skipna ):
19
23
# We perform the same operation on the np.float64 data and check
20
24
# 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):
66
70
67
71
tm .assert_extension_array_equal (result1 , expected )
68
72
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
-
86
73
@pytest .mark .parametrize ("skipna" , [True , False ])
87
74
def test_reduce_series_boolean (self , data , all_boolean_reductions , skipna ):
88
75
op_name = all_boolean_reductions
89
76
s = pd .Series (data )
90
77
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
+ )
95
83
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 )
98
86
87
+ else :
88
+ self .check_reduce (s , op_name , skipna )
99
89
100
- class BaseNumericReduceTests (BaseReduceTests ):
101
90
@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 ):
103
92
op_name = all_numeric_reductions
104
93
s = pd .Series (data )
105
94
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 )
110
109
111
110
@pytest .mark .parametrize ("skipna" , [True , False ])
112
111
def test_reduce_frame (self , data , all_numeric_reductions , skipna ):
@@ -118,12 +117,28 @@ def test_reduce_frame(self, data, all_numeric_reductions, skipna):
118
117
if op_name in ["count" , "kurt" , "sem" ]:
119
118
pytest .skip (f"{ op_name } not an array method" )
120
119
120
+ if not self ._supports_reduction (s , op_name ):
121
+ pytest .skip (f"Reduction { op_name } not supported for this dtype" )
122
+
121
123
self .check_reduce_frame (s , op_name , skipna )
122
124
123
125
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
+
124
139
class 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