Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TST Changes assert to pytest style in tests/test_random_projection.py #19846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

LSturtew
Copy link
Contributor

@LSturtew LSturtew commented Apr 8, 2021

Reference Issues/PRs

References #14216

What does this implement/fix? Explain your changes.

Changed the assert_raises, assert_message, assert_warns in tests/test_random_projection.py to pytest.raises()/pytest.warns().

Any other comments?

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @LSturtew !

Comment on lines 60 to 64
with pytest.raises(ValueError):
johnson_lindenstrauss_min_dim(100, eps=1.1)
johnson_lindenstrauss_min_dim(100, eps=0.0)
johnson_lindenstrauss_min_dim(100, eps=-0.1)
johnson_lindenstrauss_min_dim(0, eps=0.5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only check the first call because it would error first. The other calls to johnson_lindenstrauss_min_dim would not run. Can adjust this test to use pytest.mark.parametrize?:

@pytest.mark.parametrize("n_samples, eps", [
    (100, 1.1),
    (100, 0.0),
    (100, -0.1),
    (0, 0.5)
])
def test_invalid_jl_domain(n_samples, eps):
    with pytest.raises(ValueError):
        johnson_lindenstrauss_min_dim(n_samples, eps=eps)

Comment on lines 68 to 70
with pytest.raises(ValueError):
johnson_lindenstrauss_min_dim(3 * [100], eps=2 * [0.9])
johnson_lindenstrauss_min_dim(3 * [100], eps=2 * [0.9])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can use pytest.mark.parametrize as well

sklearn/tests/test_random_projection.py Outdated Show resolved Hide resolved
sklearn/tests/test_random_projection.py Show resolved Hide resolved
sklearn/tests/test_random_projection.py Show resolved Hide resolved
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updates.

I made some suggestions that overrides my previous ones.

Comment on lines 83 to 87
def check_input_size_random_matrix(random_matrix):
assert_raises(ValueError, random_matrix, 0, 0)
assert_raises(ValueError, random_matrix, -1, 1)
assert_raises(ValueError, random_matrix, 1, -1)
assert_raises(ValueError, random_matrix, 1, 0)
assert_raises(ValueError, random_matrix, -1, 0)
@pytest.mark.parametrize("random_matrix", all_random_matrix)
@pytest.mark.parametrize("n_components, n_features",[(0,0),(-1,1),(1,-1),(1,0),(-1,0)])
def test_input_size_random_matrix(random_matrix,n_components,n_features):
with pytest.raises(ValueError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I read this incorrectly and thought it was a test_* function. I think using a for look like check_input_with_sparse_random_matrix would be the more minimal change:

def check_input_size_random_matrix(random_matrix):
    inputs = [(0,0), (-1,1), (1,-1), (1,0), (-1,0)]
    for n_components, n_features in inputs:
        with pytest.raises(ValueError):
            random_matrix(n_components, n_features)

This way test_basic_property_of_random_matrix does not need to change.

sklearn/tests/test_random_projection.py Show resolved Hide resolved
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just one minor comment

Comment on lines 71 to 73
@pytest.mark.parametrize("n_samples, eps", [
(3 * [100], 2 * [0.9]), (3 * [100], 2 * [0.9])
])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 2 sets of parameters are the same. We can remove the parametrization

@jeremiedbb jeremiedbb merged commit 80e985b into scikit-learn:main Apr 9, 2021
@jeremiedbb
Copy link
Member

Thanks @LSturtew !

thomasjpfan pushed a commit to thomasjpfan/scikit-learn that referenced this pull request Apr 19, 2021
@glemaitre glemaitre mentioned this pull request Apr 22, 2021
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.