Skip to content

Commit dca6901

Browse files
authored
no need for suffix anymore (#44034)
1 parent f06d987 commit dca6901

File tree

1 file changed

+46
-62
lines changed

1 file changed

+46
-62
lines changed

pandas/tests/libs/test_hashtable.py

+46-62
Original file line numberDiff line numberDiff line change
@@ -370,96 +370,85 @@ def test_unique_for_nan_objects_tuple():
370370
assert len(unique) == 2
371371

372372

373-
def get_ht_function(fun_name, type_suffix):
374-
return getattr(ht, fun_name)
375-
376-
377373
@pytest.mark.parametrize(
378-
"dtype, type_suffix",
374+
"dtype",
379375
[
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,
394390
],
395391
)
396392
class TestHelpFunctions:
397-
def test_value_count(self, dtype, type_suffix, writable):
393+
def test_value_count(self, dtype, writable):
398394
N = 43
399-
value_count = get_ht_function("value_count", type_suffix)
400395
expected = (np.arange(N) + N).astype(dtype)
401396
values = np.repeat(expected, 5)
402397
values.flags.writeable = writable
403-
keys, counts = value_count(values, False)
398+
keys, counts = ht.value_count(values, False)
404399
tm.assert_numpy_array_equal(np.sort(keys), expected)
405400
assert np.all(counts == 5)
406401

407-
def test_value_count_stable(self, dtype, type_suffix, writable):
402+
def test_value_count_stable(self, dtype, writable):
408403
# GH12679
409-
value_count = get_ht_function("value_count", type_suffix)
410404
values = np.array([2, 1, 5, 22, 3, -1, 8]).astype(dtype)
411405
values.flags.writeable = writable
412-
keys, counts = value_count(values, False)
406+
keys, counts = ht.value_count(values, False)
413407
tm.assert_numpy_array_equal(keys, values)
414408
assert np.all(counts == 1)
415409

416-
def test_duplicated_first(self, dtype, type_suffix, writable):
410+
def test_duplicated_first(self, dtype, writable):
417411
N = 100
418-
duplicated = get_ht_function("duplicated", type_suffix)
419412
values = np.repeat(np.arange(N).astype(dtype), 5)
420413
values.flags.writeable = writable
421-
result = duplicated(values)
414+
result = ht.duplicated(values)
422415
expected = np.ones_like(values, dtype=np.bool_)
423416
expected[::5] = False
424417
tm.assert_numpy_array_equal(result, expected)
425418

426-
def test_ismember_yes(self, dtype, type_suffix, writable):
419+
def test_ismember_yes(self, dtype, writable):
427420
N = 127
428-
ismember = get_ht_function("ismember", type_suffix)
429421
arr = np.arange(N).astype(dtype)
430422
values = np.arange(N).astype(dtype)
431423
arr.flags.writeable = writable
432424
values.flags.writeable = writable
433-
result = ismember(arr, values)
425+
result = ht.ismember(arr, values)
434426
expected = np.ones_like(values, dtype=np.bool_)
435427
tm.assert_numpy_array_equal(result, expected)
436428

437-
def test_ismember_no(self, dtype, type_suffix):
429+
def test_ismember_no(self, dtype):
438430
N = 17
439-
ismember = get_ht_function("ismember", type_suffix)
440431
arr = np.arange(N).astype(dtype)
441432
values = (np.arange(N) + N).astype(dtype)
442-
result = ismember(arr, values)
433+
result = ht.ismember(arr, values)
443434
expected = np.zeros_like(values, dtype=np.bool_)
444435
tm.assert_numpy_array_equal(result, expected)
445436

446-
def test_mode(self, dtype, type_suffix, writable):
437+
def test_mode(self, dtype, writable):
447438
if dtype in (np.int8, np.uint8):
448439
N = 53
449440
else:
450441
N = 11111
451-
mode = get_ht_function("mode", type_suffix)
452442
values = np.repeat(np.arange(N).astype(dtype), 5)
453443
values[0] = 42
454444
values.flags.writeable = writable
455-
result = mode(values, False)
445+
result = ht.mode(values, False)
456446
assert result == 42
457447

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):
460449
values = np.array([2, 1, 5, 22, 3, -1, 8]).astype(dtype)
461450
values.flags.writeable = writable
462-
keys = mode(values, False)
451+
keys = ht.mode(values, False)
463452
tm.assert_numpy_array_equal(keys, values)
464453

465454

@@ -482,52 +471,47 @@ def test_unique_label_indices_intp(writable):
482471

483472

484473
@pytest.mark.parametrize(
485-
"dtype, type_suffix",
474+
"dtype",
486475
[
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,
491480
],
492481
)
493482
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):
496484
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)
498486
assert len(keys) == 0
499-
keys, counts = value_count(values, False)
487+
keys, counts = ht.value_count(values, False)
500488
assert len(keys) == 1 and np.all(np.isnan(keys))
501489
assert counts[0] == 3
502490

503-
def test_duplicated_first(self, dtype, type_suffix):
504-
duplicated = get_ht_function("duplicated", type_suffix)
491+
def test_duplicated_first(self, dtype):
505492
values = np.array([np.nan, np.nan, np.nan], dtype=dtype)
506-
result = duplicated(values)
493+
result = ht.duplicated(values)
507494
expected = np.array([False, True, True])
508495
tm.assert_numpy_array_equal(result, expected)
509496

510-
def test_ismember_yes(self, dtype, type_suffix):
511-
ismember = get_ht_function("ismember", type_suffix)
497+
def test_ismember_yes(self, dtype):
512498
arr = np.array([np.nan, np.nan, np.nan], dtype=dtype)
513499
values = np.array([np.nan, np.nan], dtype=dtype)
514-
result = ismember(arr, values)
500+
result = ht.ismember(arr, values)
515501
expected = np.array([True, True, True], dtype=np.bool_)
516502
tm.assert_numpy_array_equal(result, expected)
517503

518-
def test_ismember_no(self, dtype, type_suffix):
519-
ismember = get_ht_function("ismember", type_suffix)
504+
def test_ismember_no(self, dtype):
520505
arr = np.array([np.nan, np.nan, np.nan], dtype=dtype)
521506
values = np.array([1], dtype=dtype)
522-
result = ismember(arr, values)
507+
result = ht.ismember(arr, values)
523508
expected = np.array([False, False, False], dtype=np.bool_)
524509
tm.assert_numpy_array_equal(result, expected)
525510

526-
def test_mode(self, dtype, type_suffix):
527-
mode = get_ht_function("mode", type_suffix)
511+
def test_mode(self, dtype):
528512
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))
531515

532516

533517
def test_ismember_tuple_with_nans():

0 commit comments

Comments
 (0)