peacock-data-public-datasets-idc-cronscript
/
venv
/lib
/python3.10
/site-packages
/sklearn
/utils
/tests
/test_fixes.py
# Authors: Gael Varoquaux <[email protected]> | |
# Justin Vincent | |
# Lars Buitinck | |
# License: BSD 3 clause | |
import numpy as np | |
import pytest | |
from sklearn.utils._testing import assert_array_equal | |
from sklearn.utils.fixes import ( | |
_object_dtype_isnan, | |
_smallest_admissible_index_dtype, | |
delayed, | |
) | |
def test_object_dtype_isnan(dtype, val): | |
X = np.array([[val, np.nan], [np.nan, val]], dtype=dtype) | |
expected_mask = np.array([[False, True], [True, False]]) | |
mask = _object_dtype_isnan(X) | |
assert_array_equal(mask, expected_mask) | |
def test_delayed_deprecation(): | |
"""Check that we issue the FutureWarning regarding the deprecation of delayed.""" | |
def func(x): | |
return x | |
warn_msg = "The function `delayed` has been moved from `sklearn.utils.fixes`" | |
with pytest.warns(FutureWarning, match=warn_msg): | |
delayed(func) | |
def test_smallest_admissible_index_dtype_max_val(params, expected_dtype): | |
"""Check the behaviour of `smallest_admissible_index_dtype` depending only on the | |
`max_val` parameter. | |
""" | |
assert _smallest_admissible_index_dtype(**params) == expected_dtype | |
def test_smallest_admissible_index_dtype_without_checking_contents( | |
params, expected_dtype | |
): | |
"""Check the behaviour of `smallest_admissible_index_dtype` using the passed | |
arrays but without checking the contents of the arrays. | |
""" | |
assert _smallest_admissible_index_dtype(**params) == expected_dtype | |
def test_smallest_admissible_index_dtype_by_checking_contents(params, expected_dtype): | |
"""Check the behaviour of `smallest_admissible_index_dtype` using the dtype of the | |
arrays but as well the contents. | |
""" | |
assert _smallest_admissible_index_dtype(**params) == expected_dtype | |
def test_smallest_admissible_index_dtype_error(params, err_type, err_msg): | |
"""Check that we raise the proper error message.""" | |
with pytest.raises(err_type, match=err_msg): | |
_smallest_admissible_index_dtype(**params) | |