Skip to content
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

[MRG]Replaced all occurrences of assert_true() and assert_false() with assert. #12588

Merged
merged 5 commits into from Nov 28, 2018
Merged

Conversation

jaskola8
Copy link
Contributor

Reference Issues/PRs

#12580

What does this implement/fix? Explain your changes.

Replaced all occurrences of assert_true() and assert_false() with assert, kept definitions of replaced functions in sklearn.utils.testing.

Any other comments?

Tested with pytest, flake8 and by using make.

…ert and assert not, kept definitions of replaced functions. Tested with pytest, flake8 and by using make.
@jnothman
Copy link
Member

Flake8 is not happy

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

A few comments are below. Generally a few remarks (I have not commented in all the places where these apply),

  • in assert not(result), parentheses are not needed, use assert not result.
  • For line breaks in assert, see https://stackoverflow.com/a/16065512/1791279
    I find it OK (for lack of better alternatives) to use line break for a single line, e.g.
    assert result, \
         "some long error message"
    however, when you get more than one line, use parentheses,
       assert result, (
         "some long error message: {}"
         "another line" 
         .format(custom_message))

sklearn/cluster/tests/test_affinity_propagation.py Outdated Show resolved Hide resolved
sklearn/feature_extraction/tests/test_text.py Outdated Show resolved Hide resolved
sklearn/model_selection/tests/test_validation.py Outdated Show resolved Hide resolved
sklearn/utils/mocking.py Outdated Show resolved Hide resolved
sklearn/utils/tests/test_multiclass.py Outdated Show resolved Hide resolved
@jaskola8
Copy link
Contributor Author

Thanks for feedback! I'll clean this up today.

@qinhanmin2014
Copy link
Member

@jaskola8 any updates?

@jaskola8 jaskola8 changed the title [MRG] Replaced all occurrences of assert_true() and assert_false() with assert. Replaced all occurrences of assert_true() and assert_false() with assert. Nov 26, 2018
@jaskola8 jaskola8 changed the title Replaced all occurrences of assert_true() and assert_false() with assert. [WIP]Replaced all occurrences of assert_true() and assert_false() with assert. Nov 26, 2018
…embership cleanup) for first half of tests (including models_selection/tests/test_validation.py).
@qinhanmin2014
Copy link
Member

@jaskola8 Why WIP? You don't need to worry about the first job of Travis now. ping when it's ready for a second review.

@jaskola8
Copy link
Contributor Author

jaskola8 commented Nov 27, 2018

I wasn't sure how to indicate that this branch is not ready for merge so i changed [MRG] to [WIP]. If integration tests running now will be successful i will change it to [MRG].

@jaskola8 jaskola8 changed the title [WIP]Replaced all occurrences of assert_true() and assert_false() with assert. [MRG]Replaced all occurrences of assert_true() and assert_false() with assert. Nov 27, 2018
Copy link
Member

@rth rth 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 this work @jaskola8 !

A few minor comments below, but apart from that this LGTM.

'MockClassifier extra fit_param '
'sample_weight.shape[0]'
' is {0}, should be {1}'.format(sample_weight.shape[0],
X.shape[0]))
Copy link
Member

Choose a reason for hiding this comment

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

Nit (only if you do changes for other reviewers), this could be more nicely written as,

                'sample_weight.shape[0] is {0}, should be {1}'
                .format(sample_weight.shape[0], X.shape[0]))

@@ -61,8 +61,8 @@ def check_l1_min_c(X, y, loss, fit_intercept=True, intercept_scaling=None):

clf.C = min_c * 1.01
clf.fit(X, y)
assert_true((np.asarray(clf.coef_) != 0).any() or
(np.asarray(clf.intercept_) != 0).any())
assert (np.asarray(clf.coef_) != 0).any() or \
Copy link
Member

Choose a reason for hiding this comment

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

Better to use the parenthesis here I think,

    assert ((np.asarray(clf.coef_) != 0).any() or
            (np.asarray(clf.intercept_) != 0).any())

hasattr(MetaEstTestList(HasPredict(), HasPredict()), 'predict'))
assert not hasattr(MetaEst(HasNoPredict()), 'predict')
assert not \
hasattr(MetaEstTestTuple(HasNoPredict(), HasNoPredict()), 'predict')
Copy link
Member

Choose a reason for hiding this comment

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

also,

    assert not hasattr(MetaEstTestTuple(HasNoPredict(), HasNoPredict()),
                       'predict')

or something similar if this is too long.

assert hasattr(MetaEstTestTuple(HasPredict(), HasNoPredict()), 'predict')
assert not \
hasattr(MetaEstTestTuple(HasNoPredict(), HasPredict()), 'predict')
assert not \
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

X.dtype == X_checked.dtype and
X_checked.flags['C_CONTIGUOUS'] == X.flags['C_CONTIGUOUS'] and
X_checked.flags['F_CONTIGUOUS'] == X.flags['F_CONTIGUOUS']
):
Copy link
Member

Choose a reason for hiding this comment

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

This is an unrelated change I think? I'm not convinced the new formatting is much better, better to revert this.

@jaskola8
Copy link
Contributor Author

Thank you for your feedback, should I apply changes you mentioned above or leave it as it is?

@rth
Copy link
Member

rth commented Nov 27, 2018

The first one was optionally, but if you could fix the other ones it would be great.

Thanks again for contributing!

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.

thanks @jaskola8

@qinhanmin2014 qinhanmin2014 merged commit fa98a72 into scikit-learn:master Nov 28, 2018
@jaskola8 jaskola8 deleted the issue12580 branch November 28, 2018 09:36
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
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.

None yet

4 participants