@@ -370,96 +370,85 @@ def test_unique_for_nan_objects_tuple():
370
370
assert len (unique ) == 2
371
371
372
372
373
- def get_ht_function (fun_name , type_suffix ):
374
- return getattr (ht , fun_name )
375
-
376
-
377
373
@pytest .mark .parametrize (
378
- "dtype, type_suffix " ,
374
+ "dtype" ,
379
375
[
380
- ( np .object_ , "object" ) ,
381
- ( np .complex128 , "complex128" ) ,
382
- ( np .int64 , "int64" ) ,
383
- ( np .uint64 , "uint64" ) ,
384
- ( np .float64 , "float64" ) ,
385
- ( np .complex64 , "complex64" ) ,
386
- ( np .int32 , "int32" ) ,
387
- ( np .uint32 , "uint32" ) ,
388
- ( np .float32 , "float32" ) ,
389
- ( np .int16 , "int16" ) ,
390
- ( np .uint16 , "uint16" ) ,
391
- ( np .int8 , "int8" ) ,
392
- ( np .uint8 , "uint8" ) ,
393
- ( np .intp , "intp" ) ,
376
+ np .object_ ,
377
+ np .complex128 ,
378
+ np .int64 ,
379
+ np .uint64 ,
380
+ np .float64 ,
381
+ np .complex64 ,
382
+ np .int32 ,
383
+ np .uint32 ,
384
+ np .float32 ,
385
+ np .int16 ,
386
+ np .uint16 ,
387
+ np .int8 ,
388
+ np .uint8 ,
389
+ np .intp ,
394
390
],
395
391
)
396
392
class TestHelpFunctions :
397
- def test_value_count (self , dtype , type_suffix , writable ):
393
+ def test_value_count (self , dtype , writable ):
398
394
N = 43
399
- value_count = get_ht_function ("value_count" , type_suffix )
400
395
expected = (np .arange (N ) + N ).astype (dtype )
401
396
values = np .repeat (expected , 5 )
402
397
values .flags .writeable = writable
403
- keys , counts = value_count (values , False )
398
+ keys , counts = ht . value_count (values , False )
404
399
tm .assert_numpy_array_equal (np .sort (keys ), expected )
405
400
assert np .all (counts == 5 )
406
401
407
- def test_value_count_stable (self , dtype , type_suffix , writable ):
402
+ def test_value_count_stable (self , dtype , writable ):
408
403
# GH12679
409
- value_count = get_ht_function ("value_count" , type_suffix )
410
404
values = np .array ([2 , 1 , 5 , 22 , 3 , - 1 , 8 ]).astype (dtype )
411
405
values .flags .writeable = writable
412
- keys , counts = value_count (values , False )
406
+ keys , counts = ht . value_count (values , False )
413
407
tm .assert_numpy_array_equal (keys , values )
414
408
assert np .all (counts == 1 )
415
409
416
- def test_duplicated_first (self , dtype , type_suffix , writable ):
410
+ def test_duplicated_first (self , dtype , writable ):
417
411
N = 100
418
- duplicated = get_ht_function ("duplicated" , type_suffix )
419
412
values = np .repeat (np .arange (N ).astype (dtype ), 5 )
420
413
values .flags .writeable = writable
421
- result = duplicated (values )
414
+ result = ht . duplicated (values )
422
415
expected = np .ones_like (values , dtype = np .bool_ )
423
416
expected [::5 ] = False
424
417
tm .assert_numpy_array_equal (result , expected )
425
418
426
- def test_ismember_yes (self , dtype , type_suffix , writable ):
419
+ def test_ismember_yes (self , dtype , writable ):
427
420
N = 127
428
- ismember = get_ht_function ("ismember" , type_suffix )
429
421
arr = np .arange (N ).astype (dtype )
430
422
values = np .arange (N ).astype (dtype )
431
423
arr .flags .writeable = writable
432
424
values .flags .writeable = writable
433
- result = ismember (arr , values )
425
+ result = ht . ismember (arr , values )
434
426
expected = np .ones_like (values , dtype = np .bool_ )
435
427
tm .assert_numpy_array_equal (result , expected )
436
428
437
- def test_ismember_no (self , dtype , type_suffix ):
429
+ def test_ismember_no (self , dtype ):
438
430
N = 17
439
- ismember = get_ht_function ("ismember" , type_suffix )
440
431
arr = np .arange (N ).astype (dtype )
441
432
values = (np .arange (N ) + N ).astype (dtype )
442
- result = ismember (arr , values )
433
+ result = ht . ismember (arr , values )
443
434
expected = np .zeros_like (values , dtype = np .bool_ )
444
435
tm .assert_numpy_array_equal (result , expected )
445
436
446
- def test_mode (self , dtype , type_suffix , writable ):
437
+ def test_mode (self , dtype , writable ):
447
438
if dtype in (np .int8 , np .uint8 ):
448
439
N = 53
449
440
else :
450
441
N = 11111
451
- mode = get_ht_function ("mode" , type_suffix )
452
442
values = np .repeat (np .arange (N ).astype (dtype ), 5 )
453
443
values [0 ] = 42
454
444
values .flags .writeable = writable
455
- result = mode (values , False )
445
+ result = ht . mode (values , False )
456
446
assert result == 42
457
447
458
- def test_mode_stable (self , dtype , type_suffix , writable ):
459
- mode = get_ht_function ("mode" , type_suffix )
448
+ def test_mode_stable (self , dtype , writable ):
460
449
values = np .array ([2 , 1 , 5 , 22 , 3 , - 1 , 8 ]).astype (dtype )
461
450
values .flags .writeable = writable
462
- keys = mode (values , False )
451
+ keys = ht . mode (values , False )
463
452
tm .assert_numpy_array_equal (keys , values )
464
453
465
454
@@ -482,52 +471,47 @@ def test_unique_label_indices_intp(writable):
482
471
483
472
484
473
@pytest .mark .parametrize (
485
- "dtype, type_suffix " ,
474
+ "dtype" ,
486
475
[
487
- ( np .float64 , "float64" ) ,
488
- ( np .float32 , "float32" ) ,
489
- ( np .complex128 , "complex128" ) ,
490
- ( np .complex64 , "complex64" ) ,
476
+ np .float64 ,
477
+ np .float32 ,
478
+ np .complex128 ,
479
+ np .complex64 ,
491
480
],
492
481
)
493
482
class TestHelpFunctionsWithNans :
494
- def test_value_count (self , dtype , type_suffix ):
495
- value_count = get_ht_function ("value_count" , type_suffix )
483
+ def test_value_count (self , dtype ):
496
484
values = np .array ([np .nan , np .nan , np .nan ], dtype = dtype )
497
- keys , counts = value_count (values , True )
485
+ keys , counts = ht . value_count (values , True )
498
486
assert len (keys ) == 0
499
- keys , counts = value_count (values , False )
487
+ keys , counts = ht . value_count (values , False )
500
488
assert len (keys ) == 1 and np .all (np .isnan (keys ))
501
489
assert counts [0 ] == 3
502
490
503
- def test_duplicated_first (self , dtype , type_suffix ):
504
- duplicated = get_ht_function ("duplicated" , type_suffix )
491
+ def test_duplicated_first (self , dtype ):
505
492
values = np .array ([np .nan , np .nan , np .nan ], dtype = dtype )
506
- result = duplicated (values )
493
+ result = ht . duplicated (values )
507
494
expected = np .array ([False , True , True ])
508
495
tm .assert_numpy_array_equal (result , expected )
509
496
510
- def test_ismember_yes (self , dtype , type_suffix ):
511
- ismember = get_ht_function ("ismember" , type_suffix )
497
+ def test_ismember_yes (self , dtype ):
512
498
arr = np .array ([np .nan , np .nan , np .nan ], dtype = dtype )
513
499
values = np .array ([np .nan , np .nan ], dtype = dtype )
514
- result = ismember (arr , values )
500
+ result = ht . ismember (arr , values )
515
501
expected = np .array ([True , True , True ], dtype = np .bool_ )
516
502
tm .assert_numpy_array_equal (result , expected )
517
503
518
- def test_ismember_no (self , dtype , type_suffix ):
519
- ismember = get_ht_function ("ismember" , type_suffix )
504
+ def test_ismember_no (self , dtype ):
520
505
arr = np .array ([np .nan , np .nan , np .nan ], dtype = dtype )
521
506
values = np .array ([1 ], dtype = dtype )
522
- result = ismember (arr , values )
507
+ result = ht . ismember (arr , values )
523
508
expected = np .array ([False , False , False ], dtype = np .bool_ )
524
509
tm .assert_numpy_array_equal (result , expected )
525
510
526
- def test_mode (self , dtype , type_suffix ):
527
- mode = get_ht_function ("mode" , type_suffix )
511
+ def test_mode (self , dtype ):
528
512
values = np .array ([42 , np .nan , np .nan , np .nan ], dtype = dtype )
529
- assert mode (values , True ) == 42
530
- assert np .isnan (mode (values , False ))
513
+ assert ht . mode (values , True ) == 42
514
+ assert np .isnan (ht . mode (values , False ))
531
515
532
516
533
517
def test_ismember_tuple_with_nans ():
0 commit comments