Repository: scikit-learn/scikit-learn
File: sklearn/tests/test_base.py (Python)

Code before:
        (None, KFold()),
        (None, get_scorer("accuracy")),
    ],
)
def test_param_is_non_default(default_value, test_value):
    """Check that we detect non-default parameters with various types.

    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/31525
    """
    estimator = make_estimator_with_param(default_value)(param=test_value)
    non_default = estimator._get_params_html().non_default
    assert "param" in non_default


def test_param_is_non_default_when_pandas_NA():
    """Check that we detect pandas.Na as non-default parameter.

    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/32312
    """
    pd = pytest.importorskip("pandas")
    if pd:
        estimator = make_estimator_with_param(None)(param=pd.NA)
        non_default = estimator._get_params_html().non_default
        assert "param" in non_default


@pytest.mark.parametrize(
    "default_value, test_value",
    [
        (None, None),
        ((), ()),
        ((), []),
        ((), np.array([])),
        ((1, 2, 3), (1, 2, 3)),
        ((1, 2, 3), [1, 2, 3]),
        ((1, 2, 3), np.array([1, 2, 3])),
        (np.nan, np.nan),
        ("abc", "abc"),
        (True, True),
        (1, 1),
        (1.0, 1.0),
        (2, 2.0),
    ],
)
def test_param_is_default(default_value, test_value):
    """Check that we detect the default parameters and values in an array-like will
    be reported as default as well.

    Non-regression test for:

Review comment (suggestion):
no need to check for `pd` afterwards since the `importorskip` would have make pytest skip the test anyway.
```suggestion
    estimator = make_estimator_with_param(None)(param=pd.NA)
    non_default = estimator._get_params_html().non_default
    assert "param" in non_default
```

Code after:
        (None, KFold()),
        (None, get_scorer("accuracy")),
    ],
)
def test_param_is_non_default(default_value, test_value):
    """Check that we detect non-default parameters with various types.

    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/31525
    """
    estimator = make_estimator_with_param(default_value)(param=test_value)
    non_default = estimator._get_params_html().non_default
    assert "param" in non_default


def test_param_is_non_default_when_pandas_NA():
    """Check that we detect pandas.Na as non-default parameter.

    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/32312
    """
    pd = pytest.importorskip("pandas")

    estimator = make_estimator_with_param(default_value=0)(param=pd.NA)
    non_default = estimator._get_params_html().non_default
    assert "param" in non_default


@pytest.mark.parametrize(
    "default_value, test_value",
    [
        (None, None),
        ((), ()),
        ((), []),
        ((), np.array([])),
        ((1, 2, 3), (1, 2, 3)),
        ((1, 2, 3), [1, 2, 3]),
        ((1, 2, 3), np.array([1, 2, 3])),
        (np.nan, np.nan),
        ("abc", "abc"),
        (True, True),
        (1, 1),
        (1.0, 1.0),
        (2, 2.0),
    ],
)
def test_param_is_default(default_value, test_value):
    """Check that we detect the default parameters and values in an array-like will
    be reported as default as well.

    Non-regression test for: