Skip to content

RF: autoreplace assert_true(...==...) with plain assert #12547

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 5 commits into from
Nov 11, 2018

Conversation

yarikoptic
Copy link
Member

@yarikoptic yarikoptic commented Nov 8, 2018

It is desired since assert_true (not even assert_equal) provides no information on actual value which fails the test

  • verify/fix any possible incorrect substitution

Note: Command (git-sedi) recorded in the commit msg comes from my zshrc:

# Useful for quick refactoring
git-sedi() {
  git grep -l $1 | xargs sed -i -e "s/$1/$2/g"
}

It is desired since assert_true (not even assert_equal) provides no information
on actual value which fails the test

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "git-sedi 'assert_true(\\( *.* == .*\\) *)$' 'assert \\1'",
 "exit": 0,
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^
@amueller
Copy link
Member

amueller commented Nov 8, 2018

invaid syntax ;)



def check_cv_results_keys(cv_results, param_keys, score_keys, n_cand):
# Test the search.cv_results_ contains all the required results
assert_array_equal(sorted(cv_results.keys()),
sorted(param_keys + score_keys + ('params',)))
assert_true(all(cv_results[key].shape == (n_cand,)
assert all(cv_results[key].shape == (n_cand,
Copy link
Member

Choose a reason for hiding this comment

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

invalid syntax here I think?

Copy link
Contributor

Choose a reason for hiding this comment

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

also I see that the assert change from the original, is not?

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 -- the 'cons' of auto sed. will need to fix them up - didn't spot on a brief eye balling

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "git-sedi 'assert_true( *\\(.*\\) *) *$' 'assert \\1'",
 "exit": 0,
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^
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.

We also need to remove relevant imports

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.

+1 for removing unused imports, we could also do the same thing for assert_equal in a follow-up PR.

I would even suggest including this in 0.20.1 as it shouldn't affect users, but make understanding test failure logs easier.

There was an earlier discussion about the possibility of creating merge conflicts (can't find it anymore), but in this case, I think it's worth it.

@qinhanmin2014
Copy link
Member

Fine with 0.20.1, as long as we can finish it.

@rth Maybe we don't need to do the same thing for assert_equal? We can still get things like AssertionError: a != b if we use assert_equal.

@amueller
Copy link
Member

I don't think there's a very strong incentive for assert_equal, so I wouldn't prioritize it?

Copy link
Member

@amueller amueller left a comment

Choose a reason for hiding this comment

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

would be nice to remove unused imports but that's manual work so I'd be fine with a separate PR.

@qinhanmin2014 qinhanmin2014 merged commit 362cb3b into scikit-learn:master Nov 11, 2018
@stsouko
Copy link

stsouko commented Nov 11, 2018

assert_true(all([not isinstance(est, RandomForestClassifier) for est in
                     eclf2.estimators_]))

checks like this not fixed.

@qinhanmin2014
Copy link
Member

@stsouko Yes, this PR is not complete. One issue for some assert_true is how to handle the message. I think a PR to remove other assert_true is welcomed.

@jnothman
Copy link
Member

jnothman commented Nov 12, 2018 via email

@qinhanmin2014
Copy link
Member

What's hard about handling the message? The assert statement allows for a
message

You're right, apologies for the stupid comment.

@stsouko Would you like to submit a PR? Otherwise I'll open an issue.

@stsouko
Copy link

stsouko commented Nov 12, 2018

At this moment I did a #12513. This assertion refers to the tests of voting classifier module. I fixed this test in PR.

@qinhanmin2014
Copy link
Member

@stsouko please do it in a separate PR, thanks

@stsouko
Copy link

stsouko commented Nov 12, 2018

I can do full fix of voting tests. according to this conclusion. Is it OK?

@qinhanmin2014
Copy link
Member

It's better to fix a single issue in each PR.

@stsouko
Copy link

stsouko commented Nov 12, 2018

done.

thoo added a commit to thoo/scikit-learn that referenced this pull request Nov 12, 2018
…ybutton

* upstream/master:
  FIX remove FutureWarning in _object_dtype_isnan and add test (scikit-learn#12567)
  DOC Add 's' to "correspond" in docs for Hamming Loss. (scikit-learn#12565)
  EXA Fix comment in plot-iris-logistic example (scikit-learn#12564)
  FIX stop words validation in text vectorizers with custom preprocessors / tokenizers (scikit-learn#12393)
  DOC Add skorch to related projects (scikit-learn#12561)
  MNT Don't change self.n_values in OneHotEncoder.fit (scikit-learn#12286)
  MNT Remove unused assert_true imports (scikit-learn#12560)
  TST autoreplace assert_true(...==...) with plain assert (scikit-learn#12547)
  DOC: add a testimonial from JP Morgan (scikit-learn#12555)
thoo pushed a commit to thoo/scikit-learn that referenced this pull request Nov 13, 2018
thoo added a commit to thoo/scikit-learn that referenced this pull request Nov 13, 2018
…ikit-learn into add_codeblock_copybutton

* 'add_codeblock_copybutton' of https://github.com/thoo/scikit-learn:
  Move an extension under sphinx_copybutton/
  Move css/js file under sphinxext/
  Fix max_depth overshoot in BFS expansion of trees (scikit-learn#12344)
  TST don't test utils.fixes docstrings (scikit-learn#12576)
  DOC Fix typo (scikit-learn#12563)
  FIX Workaround limitation of cloudpickle under PyPy (scikit-learn#12566)
  MNT bare asserts (scikit-learn#12571)
  FIX incorrect error when OneHotEncoder.transform called prior to fit (scikit-learn#12443)
  Retrigger travis:max time limit error
  DOC: Clarify `cv` parameter description in `GridSearchCV` (scikit-learn#12495)
  FIX remove FutureWarning in _object_dtype_isnan and add test (scikit-learn#12567)
  DOC Add 's' to "correspond" in docs for Hamming Loss. (scikit-learn#12565)
  EXA Fix comment in plot-iris-logistic example (scikit-learn#12564)
  FIX stop words validation in text vectorizers with custom preprocessors / tokenizers (scikit-learn#12393)
  DOC Add skorch to related projects (scikit-learn#12561)
  MNT Don't change self.n_values in OneHotEncoder.fit (scikit-learn#12286)
  MNT Remove unused assert_true imports (scikit-learn#12560)
  TST autoreplace assert_true(...==...) with plain assert (scikit-learn#12547)
  DOC: add a testimonial from JP Morgan (scikit-learn#12555)
thoo pushed a commit to thoo/scikit-learn that referenced this pull request Nov 14, 2018
jnothman pushed a commit to jnothman/scikit-learn that referenced this pull request Nov 14, 2018
jnothman pushed a commit to jnothman/scikit-learn that referenced this pull request Nov 14, 2018
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.

7 participants