Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG+1] Pytest parametrization part2 - cluster, datasets and decomposition modules #11142

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
merged 6 commits into from
Jun 1, 2018

Conversation

rth
Copy link
Member

@rth rth commented May 26, 2018

pytest parametrization of unit tests in sklearn.datasets, sklearn.cluster, sklearn.decomposition.

Part 2 of #11074, please see the parent PR for additional information.

@rth rth mentioned this pull request May 26, 2018
3 tasks
@rth rth changed the title Pytest parametrization part2 - cluster, datasets and decomposition modules [MRG] Pytest parametrization part2 - cluster, datasets and decomposition modules May 26, 2018
Copy link
Member

@lesteve lesteve left a comment

Choose a reason for hiding this comment

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

This looks nice, just a few minor comments. For other reviewers, you can disable whitespace differences in the diff, this makes this PR a lot easier to review!

_remove_dir(TEST_CATEGORY_DIR1)
@pytest.fixture
def test_category_dir_2(load_files_root):
TEST_CATEGORY_DIR2 = tempfile.mkdtemp(dir=load_files_root)
Copy link
Member

Choose a reason for hiding this comment

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

Bonus points if you remove capitalization here and everywhere else since they are not globals anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, done.

sample_file = tempfile.NamedTemporaryFile(dir=TEST_CATEGORY_DIR1,
delete=False)
sample_file.write(b("Hello World!\n"))
sample_file.close()
yield str(TEST_CATEGORY_DIR1)
Copy link
Member

Choose a reason for hiding this comment

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

I have a slight preference for .strpath which I find more explicit. It's probably the case in many other places too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but the returned object is a py.path.local see tmdir defintion. Its readme recommends using pathlib instead, and is staged for removal in 4.0 pytest-dev/pytest#1260. All of this to say that I wouldn't expect contributors to know that it has the .strpath method, and assuming that it can convert to string path correctly is the weakest assumption I can make.

Also that's the recommended approach for converting pathlib objects to str (https://www.python.org/dev/peps/pep-0428/#representing), so when the migration happen in pytest4 the code won't need to be changed.

Copy link
Member

Choose a reason for hiding this comment

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

Fine with me, I was not aware of this.

@pytest.mark.parametrize('sparsity', [0, 0.1, .5, 0.99, 1])
@pytest.mark.parametrize('n_samples', [13, 101])
@pytest.mark.parametrize('n_features', [2, 7, 41])
def test_load_with_offsets(sparsity, n_samples, n_features):
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: it would be nice to split test in two, since one part of the test does not depend of the parameters.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I can't see it. sparsity is used to make the X matrix that is then written to the f BytesOI object that is used pretty much everywhere in the test. Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

right, I missed that, sorry ...

@rth
Copy link
Member Author

rth commented May 29, 2018

Thanks for the review @lesteve ! I responded to your comments above.

@lesteve
Copy link
Member

lesteve commented May 31, 2018

LGTM

@lesteve lesteve changed the title [MRG] Pytest parametrization part2 - cluster, datasets and decomposition modules [MRG+1] Pytest parametrization part2 - cluster, datasets and decomposition modules May 31, 2018
Copy link
Member

@qinhanmin2014 qinhanmin2014 left a comment

Choose a reason for hiding this comment

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

LGTM

@qinhanmin2014 qinhanmin2014 merged commit d582e97 into scikit-learn:master Jun 1, 2018
@rth rth deleted the pytest-parametrize-part2 branch June 1, 2018 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants