8000 Make sure circular contours don't throw a warning by dstansby · Pull Request #8574 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@dstansby
Copy link
Member
@dstansby dstansby commented May 5, 2017

Fixes #8529. This feels very hacky though - is there a better way to make division by zero return np.inf and not raise a warning?

@dstansby dstansby added this to the 2.1 (next point release) milestone May 5, 2017
@jenshnielsen
Copy link
Member

You can numpy.errstate to change how this is handled. https://docs.scipy.org/doc/numpy/reference/generated/numpy.errstate.html

with np.errstate(divide='ignore', invalid='ignore'):
    b = np.arange(10)/0

Check that warning isn't thrown for circular contours

Ignore divide by zero warning
@dstansby
Copy link
Member Author

Hmm, looks like the windows build with python 2.7 and numpy 1.8 is throwing 4 warnings where there should be none on my new test.

@tacaswell
Copy link
Member

The warnings are coming from the ceil in line 456 not the warnings you fixed.

I am confused why none of the other configuration raise it.

Appveyor is using numpy 1.12.1 from the defaults channel.

@dstansby
Copy link
Member Author

I've added another error ignore statement to catch that error - it seems to be raising when np.ceil is passed np.nan as a value.

dist = np.add.reduce(([(abs(s)[i] / L[i]) for i in range(xsize)]), -1)
# Ignore warning that divide by zero throws, as this is a valid option
with np.errstate(divide='ignore', invalid='ignore'):
dist = np.add.reduce(([(abs(s)[i] / L[i]) for i in range(xsize)]),
Copy link
Member

Choose a reason for hiding this comment

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

Extra parentheses.

Is this abs(s[:, np.newaxis]) / L[np.newaxis, :] or abs(s[np.newaxis, :]) / L[:, np.newaxis]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh? I don't think I've done anything on this line apart from move the -1) on to the next line

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the first suggestion is just cleanup. The second is a question for my curiosity if you happen to know the answer.

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 have no idea - I tried to understand what was going on here for a while but gave up...

@tacaswell tacaswell merged commit dc6441f into matplotlib:master May 29, 2017
@dstansby dstansby deleted the contour-warning branch May 29, 2017 09:50
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.

4 participants

0