27
27
import pandas as pd
28
28
29
29
30
- @pytest .fixture (
31
- params = [
32
- bool ,
33
- "uint8" ,
34
- "int32" ,
35
- "uint64" ,
36
- "float32" ,
37
- "float64" ,
38
- "complex64" ,
39
- "complex128" ,
40
- "M8[ns]" ,
41
- "m8[ns]" ,
42
- str ,
43
- bytes ,
44
- object ,
45
- ]
46
- )
47
- def any_numpy_dtype_reduced (request ):
48
- """
49
- Parameterized fixture for numpy dtypes, reduced from any_numpy_dtype.
50
-
51
- * bool
52
- * 'int32'
53
- * 'uint64'
54
- * 'float32'
55
- * 'float64'
56
- * 'complex64'
57
- * 'complex128'
58
- * 'M8[ns]'
59
- * 'M8[ns]'
60
- * str
61
- * bytes
62
- * object
63
- """
64
- return request .param
65
-
66
-
67
30
def _check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar = None ):
68
31
"""
69
32
Auxiliary function to unify testing of scalar/array promotion.
@@ -307,9 +270,9 @@ def test_maybe_promote_float_with_float(dtype, fill_value, expected_dtype):
307
270
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
308
271
309
272
310
- def test_maybe_promote_bool_with_any (any_numpy_dtype_reduced ):
273
+ def test_maybe_promote_bool_with_any (any_numpy_dtype ):
311
274
dtype = np .dtype (bool )
312
- fill_dtype = np .dtype (any_numpy_dtype_reduced )
275
+ fill_dtype = np .dtype (any_numpy_dtype )
313
276
314
277
# create array of given dtype; casts "1" to correct dtype
315
278
fill_value = np .array ([1 ], dtype = fill_dtype )[0 ]
@@ -321,8 +284,8 @@ def test_maybe_promote_bool_with_any(any_numpy_dtype_reduced):
321
284
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
322
285
323
286
324
- def test_maybe_promote_any_with_bool (any_numpy_dtype_reduced ):
325
- dtype = np .dtype (any_numpy_dtype_reduced )
287
+ def test_maybe_promote_any_with_bool (any_numpy_dtype ):
288
+ dtype = np .dtype (any_numpy_dtype )
326
289
fill_value = True
327
290
328
291
# filling anything but bool with bool casts to object
@@ -333,9 +296,9 @@ def test_maybe_promote_any_with_bool(any_numpy_dtype_reduced):
333
296
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
334
297
335
298
336
- def test_maybe_promote_bytes_with_any (bytes_dtype , any_numpy_dtype_reduced ):
299
+ def test_maybe_promote_bytes_with_any (bytes_dtype , any_numpy_dtype ):
337
300
dtype = np .dtype (bytes_dtype )
338
- fill_dtype = np .dtype (any_numpy_dtype_reduced )
301
+ fill_dtype = np .dtype (any_numpy_dtype )
339
302
340
303
# create array of given dtype; casts "1" to correct dtype
341
304
fill_value = np .array ([1 ], dtype = fill_dtype )[0 ]
@@ -347,8 +310,8 @@ def test_maybe_promote_bytes_with_any(bytes_dtype, any_numpy_dtype_reduced):
347
310
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
348
311
349
312
350
- def test_maybe_promote_any_with_bytes (any_numpy_dtype_reduced ):
351
- dtype = np .dtype (any_numpy_dtype_reduced )
313
+ def test_maybe_promote_any_with_bytes (any_numpy_dtype ):
314
+ dtype = np .dtype (any_numpy_dtype )
352
315
353
316
# create array of given dtype
354
317
fill_value = b"abc"
@@ -361,9 +324,9 @@ def test_maybe_promote_any_with_bytes(any_numpy_dtype_reduced):
361
324
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
362
325
363
326
364
- def test_maybe_promote_datetime64_with_any (datetime64_dtype , any_numpy_dtype_reduced ):
327
+ def test_maybe_promote_datetime64_with_any (datetime64_dtype , any_numpy_dtype ):
365
328
dtype = np .dtype (datetime64_dtype )
366
- fill_dtype = np .dtype (any_numpy_dtype_reduced )
329
+ fill_dtype = np .dtype (any_numpy_dtype )
367
330
368
331
# create array of given dtype; casts "1" to correct dtype
369
332
fill_value = np .array ([1 ], dtype = fill_dtype )[0 ]
@@ -390,8 +353,8 @@ def test_maybe_promote_datetime64_with_any(datetime64_dtype, any_numpy_dtype_red
390
353
],
391
354
ids = ["pd.Timestamp" , "np.datetime64" , "datetime.datetime" , "datetime.date" ],
392
355
)
393
- def test_maybe_promote_any_with_datetime64 (any_numpy_dtype_reduced , fill_value ):
394
- dtype = np .dtype (any_numpy_dtype_reduced )
356
+ def test_maybe_promote_any_with_datetime64 (any_numpy_dtype , fill_value ):
357
+ dtype = np .dtype (any_numpy_dtype )
395
358
396
359
# filling datetime with anything but datetime casts to object
397
360
if is_datetime64_dtype (dtype ):
@@ -421,9 +384,9 @@ def test_maybe_promote_any_with_datetime64(any_numpy_dtype_reduced, fill_value):
421
384
ids = ["pd.Timestamp" , "np.datetime64" , "datetime.datetime" , "datetime.date" ],
422
385
)
423
386
def test_maybe_promote_any_numpy_dtype_with_datetimetz (
424
- any_numpy_dtype_reduced , tz_aware_fixture , fill_value
387
+ any_numpy_dtype , tz_aware_fixture , fill_value
425
388
):
426
- dtype = np .dtype (any_numpy_dtype_reduced )
389
+ dtype = np .dtype (any_numpy_dtype )
427
390
fill_dtype = DatetimeTZDtype (tz = tz_aware_fixture )
428
391
429
392
fill_value = pd .Series ([fill_value ], dtype = fill_dtype )[0 ]
@@ -435,9 +398,9 @@ def test_maybe_promote_any_numpy_dtype_with_datetimetz(
435
398
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
436
399
437
400
438
- def test_maybe_promote_timedelta64_with_any (timedelta64_dtype , any_numpy_dtype_reduced ):
401
+ def test_maybe_promote_timedelta64_with_any (timedelta64_dtype , any_numpy_dtype ):
439
402
dtype = np .dtype (timedelta64_dtype )
440
- fill_dtype = np .dtype (any_numpy_dtype_reduced )
403
+ fill_dtype = np .dtype (any_numpy_dtype )
441
404
442
405
# create array of given dtype; casts "1" to correct dtype
443
406
fill_value = np .array ([1 ], dtype = fill_dtype )[0 ]
@@ -459,10 +422,8 @@ def test_maybe_promote_timedelta64_with_any(timedelta64_dtype, any_numpy_dtype_r
459
422
[pd .Timedelta (days = 1 ), np .timedelta64 (24 , "h" ), datetime .timedelta (1 )],
460
423
ids = ["pd.Timedelta" , "np.timedelta64" , "datetime.timedelta" ],
461
424
)
462
- def test_maybe_promote_any_with_timedelta64 (
463
- any_numpy_dtype_reduced , fill_value , request
464
- ):
465
- dtype = np .dtype (any_numpy_dtype_reduced )
425
+ def test_maybe_promote_any_with_timedelta64 (any_numpy_dtype , fill_value , request ):
426
+ dtype = np .dtype (any_numpy_dtype )
466
427
467
428
# filling anything but timedelta with timedelta casts to object
468
429
if is_timedelta64_dtype (dtype ):
@@ -489,9 +450,9 @@ def test_maybe_promote_any_with_timedelta64(
489
450
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
490
451
491
452
492
- def test_maybe_promote_string_with_any (string_dtype , any_numpy_dtype_reduced ):
453
+ def test_maybe_promote_string_with_any (string_dtype , any_numpy_dtype ):
493
454
dtype = np .dtype (string_dtype )
494
- fill_dtype = np .dtype (any_numpy_dtype_reduced )
455
+ fill_dtype = np .dtype (any_numpy_dtype )
495
456
496
457
# create array of given dtype; casts "1" to correct dtype
497
458
fill_value = np .array ([1 ], dtype = fill_dtype )[0 ]
@@ -503,8 +464,8 @@ def test_maybe_promote_string_with_any(string_dtype, any_numpy_dtype_reduced):
503
464
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
504
465
505
466
506
- def test_maybe_promote_any_with_string (any_numpy_dtype_reduced ):
507
- dtype = np .dtype (any_numpy_dtype_reduced )
467
+ def test_maybe_promote_any_with_string (any_numpy_dtype ):
468
+ dtype = np .dtype (any_numpy_dtype )
508
469
509
470
# create array of given dtype
510
471
fill_value = "abc"
@@ -516,9 +477,9 @@ def test_maybe_promote_any_with_string(any_numpy_dtype_reduced):
516
477
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
517
478
518
479
519
- def test_maybe_promote_object_with_any (object_dtype , any_numpy_dtype_reduced ):
480
+ def test_maybe_promote_object_with_any (object_dtype , any_numpy_dtype ):
520
481
dtype = np .dtype (object_dtype )
521
- fill_dtype = np .dtype (any_numpy_dtype_reduced )
482
+ fill_dtype = np .dtype (any_numpy_dtype )
522
483
523
484
# create array of given dtype; casts "1" to correct dtype
524
485
fill_value = np .array ([1 ], dtype = fill_dtype )[0 ]
@@ -530,8 +491,8 @@ def test_maybe_promote_object_with_any(object_dtype, any_numpy_dtype_reduced):
530
491
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
531
492
532
493
533
- def test_maybe_promote_any_with_object (any_numpy_dtype_reduced ):
534
- dtype = np .dtype (any_numpy_dtype_reduced )
494
+ def test_maybe_promote_any_with_object (any_numpy_dtype ):
495
+ dtype = np .dtype (any_numpy_dtype )
535
496
536
497
# create array of object dtype from a scalar value (i.e. passing
537
498
# dtypes.common.is_scalar), which can however not be cast to int/float etc.
@@ -544,9 +505,9 @@ def test_maybe_promote_any_with_object(any_numpy_dtype_reduced):
544
505
_check_promote (dtype , fill_value , expected_dtype , exp_val_for_scalar )
545
506
546
507
547
- def test_maybe_promote_any_numpy_dtype_with_na (any_numpy_dtype_reduced , nulls_fixture ):
508
+ def test_maybe_promote_any_numpy_dtype_with_na (any_numpy_dtype , nulls_fixture ):
548
509
fill_value = nulls_fixture
549
- dtype = np .dtype (any_numpy_dtype_reduced )
510
+ dtype = np .dtype (any_numpy_dtype )
550
511
551
512
if isinstance (fill_value , Decimal ):
552
513
# Subject to change, but ATM (When Decimal(NAN) is being added to nulls_fixture)
0 commit comments