16
16
import numpy as np
17
17
import pytest
18
18
19
+ from pandas .core .dtypes .dtypes import ExtensionDtype
20
+
19
21
import pandas as pd
20
22
import pandas ._testing as tm
21
23
from pandas .core .arrays .numpy_ import PandasArray , PandasDtype
@@ -121,7 +123,7 @@ def data_for_grouping(allow_in_pandas, dtype):
121
123
122
124
123
125
@pytest .fixture
124
- def skip_numpy_object (dtype ):
126
+ def skip_numpy_object (dtype , request ):
125
127
"""
126
128
Tests for PandasArray with nested data. Users typically won't create
127
129
these objects via `pd.array`, but they can show up through `.array`
@@ -132,14 +134,25 @@ def skip_numpy_object(dtype):
132
134
marker to either an individual test or a test class.
133
135
"""
134
136
if dtype == "object" :
135
- raise pytest .skip ("Skipping for object dtype." )
137
+ mark = pytest .mark .xfail (reason = "Fails for object dtype" )
138
+ request .node .add_marker (mark )
136
139
137
140
138
141
skip_nested = pytest .mark .usefixtures ("skip_numpy_object" )
139
142
140
143
141
144
class BaseNumPyTests :
142
- pass
145
+ @classmethod
146
+ def assert_series_equal (cls , left , right , * args , ** kwargs ):
147
+ # base class tests hard-code expected values with numpy dtypes,
148
+ # whereas we generally want the corresponding PandasDtype
149
+ if (
150
+ isinstance (right , pd .Series )
151
+ and not isinstance (right .dtype , ExtensionDtype )
152
+ and isinstance (left .dtype , PandasDtype )
153
+ ):
154
+ right = right .astype (PandasDtype (right .dtype ))
155
+ return tm .assert_series_equal (left , right , * args , ** kwargs )
143
156
144
157
145
158
class TestCasting (BaseNumPyTests , base .BaseCastingTests ):
@@ -148,24 +161,13 @@ def test_astype_str(self, data):
148
161
# ValueError: setting an array element with a sequence
149
162
super ().test_astype_str (data )
150
163
151
- @skip_nested
152
- def test_astype_string (self , data ):
153
- # GH-33465
154
- # ValueError: setting an array element with a sequence
155
- super ().test_astype_string (data )
156
-
157
164
158
165
class TestConstructors (BaseNumPyTests , base .BaseConstructorsTests ):
159
166
@pytest .mark .skip (reason = "We don't register our dtype" )
160
167
# We don't want to register. This test should probably be split in two.
161
168
def test_from_dtype (self , data ):
162
169
pass
163
170
164
- @skip_nested
165
- def test_array_from_scalars (self , data ):
166
- # ValueError: PandasArray must be 1-dimensional.
167
- super ().test_array_from_scalars (data )
168
-
169
171
@skip_nested
170
172
def test_series_constructor_scalar_with_index (self , data , dtype ):
171
173
# ValueError: Length of passed values is 1, index implies 3.
@@ -202,10 +204,16 @@ def test_loc_iloc_frame_single_dtype(self, data, request):
202
204
203
205
204
206
class TestGroupby (BaseNumPyTests , base .BaseGroupbyTests ):
205
- @skip_nested
206
207
def test_groupby_extension_apply (
207
208
self , data_for_grouping , groupby_apply_op , request
208
209
):
210
+ dummy = groupby_apply_op ([None ])
211
+ if (
212
+ isinstance (dummy , pd .Series )
213
+ and data_for_grouping .dtype .numpy_dtype == object
214
+ ):
215
+ mark = pytest .mark .xfail (reason = "raises in MultiIndex construction" )
216
+ request .node .add_marker (mark )
209
217
super ().test_groupby_extension_apply (data_for_grouping , groupby_apply_op )
210
218
211
219
@@ -225,17 +233,6 @@ def test_value_counts(self, all_data, dropna):
225
233
def test_value_counts_with_normalize (self , data ):
226
234
return super ().test_value_counts_with_normalize (data )
227
235
228
- @pytest .mark .skip (reason = "Incorrect expected" )
229
- # We have a bool dtype, so the result is an ExtensionArray
230
- # but expected is not
231
- def test_combine_le (self , data_repeated ):
232
- super ().test_combine_le (data_repeated )
233
-
234
- @skip_nested
235
- def test_combine_add (self , data_repeated ):
236
- # Not numeric
237
- super ().test_combine_add (data_repeated )
238
-
239
236
@skip_nested
240
237
def test_shift_fill_value (self , data ):
241
238
# np.array shape inference. Shift implementation fails.
@@ -258,11 +255,6 @@ def test_fillna_copy_series(self, data_missing):
258
255
# The "scalar" for this array isn't a scalar.
259
256
super ().test_fillna_copy_series (data_missing )
260
257
261
- @skip_nested
262
- def test_hash_pandas_object_works (self , data , as_frame ):
263
- # ndarray of tuples not hashable
264
- super ().test_hash_pandas_object_works (data , as_frame )
265
-
266
258
@skip_nested
267
259
def test_searchsorted (self , data_for_sorting , as_series ):
268
260
# Test setup fails.
@@ -273,41 +265,51 @@ def test_where_series(self, data, na_value, as_frame):
273
265
# Test setup fails.
274
266
super ().test_where_series (data , na_value , as_frame )
275
267
276
- @skip_nested
277
268
@pytest .mark .parametrize ("repeats" , [0 , 1 , 2 , [1 , 2 , 3 ]])
278
- def test_repeat (self , data , repeats , as_series , use_numpy ):
279
- # Fails creating expected
269
+ def test_repeat (self , data , repeats , as_series , use_numpy , request ):
270
+ if data .dtype .numpy_dtype == object and repeats != 0 :
271
+ mark = pytest .mark .xfail (reason = "mask shapes mismatch" )
272
+ request .node .add_marker (mark )
280
273
super ().test_repeat (data , repeats , as_series , use_numpy )
281
274
282
275
@pytest .mark .xfail (reason = "PandasArray.diff may fail on dtype" )
283
276
def test_diff (self , data , periods ):
284
277
return super ().test_diff (data , periods )
285
278
286
- @skip_nested
287
279
@pytest .mark .parametrize ("box" , [pd .array , pd .Series , pd .DataFrame ])
288
- def test_equals (self , data , na_value , as_series , box ):
280
+ def test_equals (self , data , na_value , as_series , box , request ):
289
281
# Fails creating with _from_sequence
282
+ if box is pd .DataFrame and data .dtype .numpy_dtype == object :
283
+ mark = pytest .mark .xfail (reason = "AssertionError in _get_same_shape_values" )
284
+ request .node .add_marker (mark )
285
+
290
286
super ().test_equals (data , na_value , as_series , box )
291
287
292
288
293
- @skip_nested
294
289
class TestArithmetics (BaseNumPyTests , base .BaseArithmeticOpsTests ):
295
290
divmod_exc = None
296
291
series_scalar_exc = None
297
292
frame_scalar_exc = None
298
293
series_array_exc = None
299
294
295
+ @skip_nested
296
+ def test_divmod (self , data ):
297
+ super ().test_divmod (data )
298
+
299
+ @skip_nested
300
300
def test_divmod_series_array (self , data ):
301
- s = pd .Series (data )
302
- self ._check_divmod_op (s , divmod , data , exc = None )
301
+ ser = pd .Series (data )
302
+ self ._check_divmod_op (ser , divmod , data , exc = None )
303
303
304
304
@pytest .mark .skip ("We implement ops" )
305
305
def test_error (self , data , all_arithmetic_operators ):
306
306
pass
307
307
308
+ @skip_nested
308
309
def test_arith_series_with_scalar (self , data , all_arithmetic_operators ):
309
310
super ().test_arith_series_with_scalar (data , all_arithmetic_operators )
310
311
312
+ @skip_nested
311
313
def test_arith_series_with_array (self , data , all_arithmetic_operators ):
312
314
super ().test_arith_series_with_array (data , all_arithmetic_operators )
313
315
@@ -316,14 +318,17 @@ class TestPrinting(BaseNumPyTests, base.BasePrintingTests):
316
318
pass
317
319
318
320
319
- @skip_nested
320
321
class TestNumericReduce (BaseNumPyTests , base .BaseNumericReduceTests ):
321
322
def check_reduce (self , s , op_name , skipna ):
322
323
result = getattr (s , op_name )(skipna = skipna )
323
324
# avoid coercing int -> float. Just cast to the actual numpy type.
324
325
expected = getattr (s .astype (s .dtype ._dtype ), op_name )(skipna = skipna )
325
326
tm .assert_almost_equal (result , expected )
326
327
328
+ @pytest .mark .parametrize ("skipna" , [True , False ])
329
+ def test_reduce_series (self , data , all_boolean_reductions , skipna ):
330
+ super ().test_reduce_series (data , all_boolean_reductions , skipna )
331
+
327
332
328
333
@skip_nested
329
334
class TestBooleanReduce (BaseNumPyTests , base .BaseBooleanReduceTests ):
@@ -364,11 +369,6 @@ def test_fillna_fill_other(self, data_missing):
364
369
365
370
366
371
class TestReshaping (BaseNumPyTests , base .BaseReshapingTests ):
367
- @pytest .mark .skip ("Incorrect parent test" )
368
- # not actually a mixed concat, since we concat int and int.
369
- def test_concat_mixed_dtypes (self , data ):
370
- super ().test_concat_mixed_dtypes (data )
371
-
372
372
@skip_nested
373
373
def test_merge (self , data , na_value ):
374
374
# Fails creating expected
@@ -390,22 +390,6 @@ def test_transpose_frame(self, data):
390
390
391
391
392
392
class TestSetitem (BaseNumPyTests , base .BaseSetitemTests ):
393
- @skip_nested
394
- def test_setitem_scalar_series (self , data , box_in_series ):
395
- # AssertionError
396
- super ().test_setitem_scalar_series (data , box_in_series )
397
-
398
- @skip_nested
399
- def test_setitem_sequence (self , data , box_in_series ):
400
- # ValueError: shape mismatch: value array of shape (2,1) could not
401
- # be broadcast to indexing result of shape (2,)
402
- super ().test_setitem_sequence (data , box_in_series )
403
-
404
- @skip_nested
405
- def test_setitem_sequence_mismatched_length_raises (self , data , as_array ):
406
- # ValueError: PandasArray must be 1-dimensional.
407
- super ().test_setitem_sequence_mismatched_length_raises (data , as_array )
408
-
409
393
@skip_nested
410
394
def test_setitem_sequence_broadcasts (self , data , box_in_series ):
411
395
# ValueError: cannot set using a list-like indexer with a different
@@ -459,7 +443,6 @@ def test_setitem_scalar_key_sequence_raise(self, data):
459
443
def test_setitem_mask (self , data , mask , box_in_series ):
460
444
super ().test_setitem_mask (data , mask , box_in_series )
461
445
462
- @skip_nested
463
446
def test_setitem_mask_raises (self , data , box_in_series ):
464
447
super ().test_setitem_mask_raises (data , box_in_series )
465
448
@@ -472,7 +455,6 @@ def test_setitem_mask_raises(self, data, box_in_series):
472
455
def test_setitem_integer_array (self , data , idx , box_in_series ):
473
456
super ().test_setitem_integer_array (data , idx , box_in_series )
474
457
475
- @skip_nested
476
458
@pytest .mark .parametrize (
477
459
"idx, box_in_series" ,
478
460
[
0 commit comments