8000 add a test for testing all _most_frequent options · DavidKatz-il/scikit-learn@20b5c87 · GitHub
[go: up one dir, main page]

Skip to content

Commit 20b5c87

Browse files
committed
add a test for testing all _most_frequent options
1 parent 56189d7 commit 20b5c87

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

sklearn/impute/tests/test_impute.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from sklearn import tree
2828
from sklearn.random_projection import _sparse_random_matrix
2929
from sklearn.exceptions import ConvergenceWarning
30+
from .._base import _most_frequent
3031

3132

3233
def _check_statistics(X, X_true,
@@ -1474,3 +1475,29 @@ def test_simple_imputation_inverse_transform_exceptions(missing_value):
14741475
with pytest.raises(ValueError,
14751476
match=f"Got 'add_indicator={imputer.add_indicator}'"):
14761477
imputer.inverse_transform(X_1_trans)
1478+
1479+
1480+
def test_most_frequent():
1481+
# collections.Counter
1482+
assert np.isnan(_most_frequent(np.array([]), 'extra_value', 0))
1483+
assert 'extra_value' == _most_frequent(
1484+
np.array(['a', 'b', 'c'], dtype=object), 'extra_value', 2
1485+
)
1486+
assert 'most_frequent' == _most_frequent(
1487+
np.array(
1488+
['most_frequent_value', 'most_frequent_value', 'value'],
1489+
dtype=object), 'extra_value', 1
1490+
)
1491+
assert 'a' == _most_frequent(np.array(
1492+
['min_value', 'min_value' 'value'], dtype=object), 'a', 2
1493+
)
1494+
assert 'min_value' == _most_frequent(
1495+
np.array(['min_value', 'min_value', 'value'], dtype=object), 'z', 2
1496+
)
1497+
1498+
# scipy.stats.mode
1499+
assert np.isnan(_most_frequent(np.array([]), 10, 0))
1500+
assert 10 == _most_frequent(np.array([1, 2, 3]), 10, 2)
1501+
assert 1 == _most_frequent(np.array([1, 1, 2]), 10, 1)
1502+
assert 10 == _most_frequent(np.array([20, 20, 1]), 10, 2)
1503+
assert 1 == _most_frequent(np.array([1, 1, 20], dtype=object), 10, 2)

0 commit comments

Comments
 (0)
0