Skip to content

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

Merged
qinhanmin2014 merged 6 commits into
scikit-learn:masterfrom
rth:pytest-parametrize-part2
Jun 1, 2018
Merged

qinhanmin2014 merged 6 commits into
scikit-learn:masterfrom
rth:pytest-parametrize-part2

Conversation

@rth

@rth rth commented May 26, 2018

Copy link
Copy Markdown
Member

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 done
@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

@lesteve lesteve left a comment

Copy link
Copy Markdown
Member

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!

Comment thread sklearn/datasets/tests/test_base.py Outdated
_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
Copy Markdown
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
Copy Markdown
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.

Comment thread sklearn/datasets/tests/test_base.py Outdated
delete=False)
sample_file.write(b("Hello World!\n"))
sample_file.close()
yield str(TEST_CATEGORY_DIR1)

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

rth commented May 29, 2018

Copy link
Copy Markdown
Member Author

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

@lesteve

lesteve commented May 31, 2018

Copy link
Copy Markdown
Member

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

@qinhanmin2014 qinhanmin2014 left a comment

Copy link
Copy Markdown
Member

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