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

Code before:
    mds_est.fit(X / 100)
    n_iter2 = mds_est.n_iter_

    assert_equal(n_iter1, n_iter2)


# TODO(1.9): delete this test
def test_future_warning_n_init():
    X = np.array([[1, 1], [1, 4], [1, 5], [3, 3]])
    sim = np.array([[0, 5, 3, 4], [5, 0, 2, 2], [3, 2, 0, 1], [4, 2, 1, 0]])

    with pytest.warns(FutureWarning):
        mds.smacof(sim)

    with pytest.warns(FutureWarning):
        mds.MDS(init="random").fit(X)


# TODO(1.9): delete the n_init warning check
# TODO(1.10): delete this test
def test_future_warning_init_and_metric():
    X = np.array([[1, 1], [1, 4], [1, 5], [3, 3]])
    sim = np.array([[0, 5, 3, 4], [5, 0, 2, 2], [3, 2, 0, 1], [4, 2, 1, 0]])

    # dissimilarity argument deprecated
    with pytest.warns(FutureWarning):
        mds.MDS(dissimilarity="precomputed", init="random", n_init=1).fit(sim)

    # metric=True deprecated
    with pytest.warns(FutureWarning):
        mds.MDS(metric=True, init="random", n_init=1).fit(X)

    # metric=False deprecated
    with pytest.warns(FutureWarning):
        mds.MDS(metric=False, init="random", n_init=1).fit(X)

    # default init will become classical_mds in the future
    with pytest.warns(FutureWarning):
        mds.MDS(metric="euclidean", n_init=1).fit(X)

    # TODO (1.9): delete this check
    # n_init=1 will become default in the future
    with pytest.warns(FutureWarning):
        mds.MDS(metric="euclidean", init="random").fit(X)

    # providing both metric and dissimilarity raises an error
    with pytest.raises(ValueError):
        mds.MDS(
            metric="cosine", dissimilarity="euclidean", init="random", n_init=1
        ).fit(X)


Review comment (suggestion):
please add a `match=...` arg to all these here to be more specific and make sure the right warning is raised

Code after:
    mds_est.fit(X / 100)
    n_iter2 = mds_est.n_iter_

    assert_equal(n_iter1, n_iter2)


# TODO(1.9): delete this test
def test_future_warning_n_init():
    X = np.array([[1, 1], [1, 4], [1, 5], [3, 3]])
    sim = np.array([[0, 5, 3, 4], [5, 0, 2, 2], [3, 2, 0, 1], [4, 2, 1, 0]])

    with pytest.warns(FutureWarning):
        mds.smacof(sim)

    with pytest.warns(FutureWarning):
        mds.MDS(init="random").fit(X)


# TODO(1.9): delete the n_init warning check
# TODO(1.10): delete this test
def test_future_warning_init_and_metric():
    X = np.array([[1, 1], [1, 4], [1, 5], [3, 3]])
    sim = np.array([[0, 5, 3, 4], [5, 0, 2, 2], [3, 2, 0, 1], [4, 2, 1, 0]])

    # dissimilarity argument deprecated
    with pytest.warns(FutureWarning, match="`dissimilarity` parameter is"):
        mds.MDS(dissimilarity="precomputed", init="random", n_init=1).fit(sim)

    # metric=True deprecated
    with pytest.warns(FutureWarning, match="Use metric_mds"):
        mds.MDS(metric=True, init="random", n_init=1).fit(X)

    # metric=False deprecated
    with pytest.warns(FutureWarning, match="Use metric_mds"):
        mds.MDS(metric=False, init="random", n_init=1).fit(X)

    # default init will become classical_mds in the future
    with pytest.warns(FutureWarning, match="The default value of `init`"):
        mds.MDS(metric="euclidean", n_init=1).fit(X)

    # TODO (1.9): delete this check
    # n_init=1 will become default in the future
    with pytest.warns(FutureWarning, match="The default value of `n_init`"):
        mds.MDS(metric="euclidean", init="random").fit(X)

    # providing both metric and dissimilarity raises an error
    with pytest.raises(ValueError, match="provided both `dissimilarity`"):
        mds.MDS(
            metric="cosine", dissimilarity="euclidean", init="random", n_init=1
        ).fit(X)