@@ -137,36 +137,47 @@ def test_select_dtypes_duplicate_col_names(include, exclude):
137137 )
138138
139139
140- @pytest .mark .parametrize (
141- "include, exclude, exc, exc_match" ,
142- [
143- ([], [], ValueError , "at least one of include or exclude must be nonempty" ),
144- (None , None , ValueError , "at least one of include or exclude must be nonempty" ),
145- # python `int` is equivalent to any np.int dtype, but it is fine for an type in
146- # `include` to be a strict subtype of a type in `exclude` or vice versa
147- (int , int , ValueError , "include and exclude overlap" ),
148- ([int ], ["O" , int ], ValueError , "include and exclude overlap" ),
149- (["O" , int ], [int ], ValueError , "include and exclude overlap" ),
150- (int , np .int32 , ValueError , "include and exclude overlap" ),
151- (int , np .int64 , ValueError , "include and exclude overlap" ),
152- ("datetime" , np .datetime64 , ValueError , "include and exclude overlap" ),
153- ("O" , object , ValueError , "include and exclude overlap" ),
154- # string dtypes are prohibited by pandas
155- (str , None , TypeError , "string dtypes are not allowed, use 'object' instead" ),
156- (None , str , TypeError , "string dtypes are not allowed, use 'object' instead" ),
157- (
158- "timedelta64[s]" ,
159- None ,
160- ValueError ,
161- "'timedelta64[s]' is too specific of a frequency, try passing 'timedelta64'" ,
140+ # Error message differs slightly across pandas patch versions
141+ STR_DTYPE_ERROR = r"string dtypes are not allowed, use ('str' or )?'object' instead"
142+
143+ SELECT_DTYPES_INVALID_PARAMS = [
144+ ([], [], ValueError , "at least one of include or exclude must be nonempty" ),
145+ (None , None , ValueError , "at least one of include or exclude must be nonempty" ),
146+ # python `int` is equivalent to any np.int dtype, but it is fine for an type in
147+ # `include` to be a strict subtype of a type in `exclude` or vice versa
148+ (int , int , ValueError , "include and exclude overlap" ),
149+ ([int ], ["O" , int ], ValueError , "include and exclude overlap" ),
150+ (["O" , int ], [int ], ValueError , "include and exclude overlap" ),
151+ (int , np .int32 , ValueError , "include and exclude overlap" ),
152+ (int , np .int64 , ValueError , "include and exclude overlap" ),
153+ ("datetime" , np .datetime64 , ValueError , "include and exclude overlap" ),
154+ ("O" , object , ValueError , "include and exclude overlap" ),
155+ # string dtypes are prohibited by pandas
156+ (str , None , TypeError , STR_DTYPE_ERROR ),
157+ (None , str , TypeError , STR_DTYPE_ERROR ),
158+ (
159+ "timedelta64[s]" ,
160+ None ,
161+ ValueError ,
162+ re .escape (
163+ "'timedelta64[s]' is too specific of a frequency, try passing 'timedelta64'"
162164 ),
163- (
164- None ,
165- "timedelta64[s]" ,
166- ValueError ,
167- "'timedelta64[s]' is too specific of a frequency, try passing 'timedelta64'" ,
165+ ),
166+ (
167+ None ,
168+ "timedelta64[s]" ,
169+ ValueError ,
170+ re .escape (
171+ "'timedelta64[s]' is too specific of a frequency, try passing 'timedelta64'"
168172 ),
169- ],
173+ ),
174+ ]
175+
176+
177+ @pytest .mark .parametrize (
178+ "include, exclude, exc, exc_match" ,
179+ SELECT_DTYPES_INVALID_PARAMS ,
180+ ids = [f"include_{ a [0 ]} -exclude_{ a [1 ]} " for a in SELECT_DTYPES_INVALID_PARAMS ],
170181)
171182@sql_count_checker (query_count = 0 )
172183def test_select_dtypes_invalid_args (include , exclude , exc , exc_match ):
@@ -178,6 +189,6 @@ def test_select_dtypes_invalid_args(include, exclude, exc, exc_match):
178189 lambda df : df .select_dtypes (include , exclude ),
179190 expect_exception = True ,
180191 expect_exception_type = exc ,
181- expect_exception_match = re . escape ( exc_match ) ,
192+ expect_exception_match = exc_match ,
182193 assert_exception_equal = True ,
183194 )
0 commit comments