-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add RuntimeWarning guard around division-by-zero #22628
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1002,6 +1002,16 @@ def test_lines_dists(): | |
ax.set_ylim(0, 300) | ||
|
||
|
||
def test_lines_dists_nowarning(): | ||
# Smoke test to see that no RuntimeWarning is emitted when two first | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be preferable to test a user-facing API rather than the private methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mostly called through mouse callbacks so it is annoying to get public API tests that exercise this. |
||
# arguments are the same, see GH#22624 | ||
p0 = (10, 30) | ||
p1 = (20, 150) | ||
proj3d._line2d_seg_dist(p0, p0, p1) | ||
p0 = np.array(p0) | ||
proj3d._line2d_seg_dist(p0, p0, p1) | ||
|
||
|
||
def test_autoscale(): | ||
fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) | ||
ax.margins(x=0, y=.1, z=.2) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your solution is technically correct. However, the issue is more a logical one rather than a technical division-by-zero problem. Therefore, I'd go with the following and leave all the original code unchanged in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the docs and removed the comment. (Kept the solution with intermediate results.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oscargus: What is the motivation for keeping this? It would be nice to give a reason if you dismiss a suggestion. I find the separation of the special case and using explicit values there more clear, but can be convinced otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to avoid duplicate code (and was a bit unsure what the effect of np.asarray was).
But I see your point about separation as well. And will try to motivate better in the future.