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

FIX: Avoid use of bare except #9133

Merged
merged 7 commits into from
Aug 23, 2018
Merged

FIX: Avoid use of bare except #9133

merged 7 commits into from
Aug 23, 2018

Conversation

larsoner
Copy link
Member

Follow-up to #9129. This PR:

  1. Removes E722 from the list of ignores in tox.ini.
  2. Replaces some instances of except: in tests with cleaner pytest.raises calls
  3. Replaces as many except:s in our code with except Exception: that seemed reasonable. In a few places there was an except: ...; raise pattern to close some other object, to which I added # noqa: E722. This works for pydocstyle and flake8-style checkers, can't remember what SciPy uses for style checking so I'll wait to see what the CIs say about it.

signal.medfilt(None)
except:
pass
signal.medfilt(None)
Copy link
Member

Choose a reason for hiding this comment

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

It raises

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests pass on my machine and CIs (except for an unrelated error). Do I need to run some special testing mode?

Copy link
Member

Choose a reason for hiding this comment

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

For the failed example, can you replace >>> print(res.x) by >>> res.x, and copy-paste the output?

It's just that the doctest checker does not understand the way numpy arrays are printed. Not sure why the error surfaces with this PR though.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, please disregard, I apparently misremember...

Copy link
Member Author

Choose a reason for hiding this comment

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

@ev-br I made a commit to try what you asked and this was the output:

File "doc/source/tutorial/optimize.rst", line 699, in /home/travis/build/scipy/scipy/tools/../doc/source/tutorial/optimize.rst
Failed example:
    res.x
Expected:
    np.array([0.41494418 0.17011164])
Got:
    array([0.41494475, 0.1701105 ])

I'm just going to put a # may vary in there for now

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought I tried a variant of this and it didn't work, but I'll open a PR to master for this. It's happening in other PRs, now, too, so I think mine was somehow just unfortunately timed to make it seem like it was due to my changes. So I'm going to revert the ones here and hopefully we can merge.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ev-br and @larsoner I think the failure is due to #9131 which changed one of the input arguments, so the expected output changes also, it should be: array([0.41494475, 0.1701105 ]) if you remove print()

Copy link
Member Author

Choose a reason for hiding this comment

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

@mikofski can you push to #9138 or open a PR to fix it? I've reverted the changes here so we can address it separately.

Copy link
Member

Choose a reason for hiding this comment

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

I've just placed a PR

@larsoner
Copy link
Member Author

All green now that master is also green and I restarted the build.

Ready for review/merge from my end

@ilayn
Copy link
Member

ilayn commented Aug 13, 2018

Looks good to me.

@rgommers rgommers added the maintenance Items related to regular maintenance tasks label Aug 23, 2018
@rgommers rgommers merged commit 10161ca into scipy:master Aug 23, 2018
@rgommers
Copy link
Member

LGTM too and all green, merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants