Skip to content

Adds runtime warning on divide-by-zero, fixes use of "out" and "where" in arctan2 - #5204

Closed
drculhane wants to merge 6 commits into
Bears-R-Us:mainfrom
drculhane:Closes-5132
Closed

drculhane wants to merge 6 commits into
Bears-R-Us:mainfrom
drculhane:Closes-5132

Conversation

@drculhane

@drculhane drculhane commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

Closes #5132. Closes #5149.

  • The binops in pdarrayclass.py now give a RuntimeWarning or a Floating Point Error (or nothing) if / or // cause a divide-by-zero, depending on the "divide" setting of ak.errstate.

  • Because the RuntimeWarning surfaced an issue in arctan2, I've rewritten that function somewhat. It now has an "out" parameter matching numpy, and uses the "where" parameter correctly.

  • Most of the original arctan2 function remains as _arctan2_, because (subjective opinion here) I think that calling it as a separate function improves the readability of the code.

  • In doing this rewriting, I removed some mypy ignores that are no longer needed.

  • I rewrote the unit tests for arctan2 to use our newer assert functions. I think this cleans up that code significantly. In the cases that use "where," I check both the returned result, and the returned "out" pdarray, since they should match.

Update:

Since other tests were also causing divide-by-zero errors, I extended the divide-by-zero check to use ak.errstate. I also bypassed additional tests in datetime once a divide-by-zero occurred, because they would also cause errors.

@ajpotts ajpotts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work!

Comment thread arkouda/numpy/numeric.py Resolved
Comment thread arkouda/numpy/numeric.py Resolved
Comment thread arkouda/numpy/numeric.py Resolved
Comment thread arkouda/numpy/numeric.py Resolved
Comment thread arkouda/numpy/numeric.py Resolved
Comment thread arkouda/numpy/numeric.py Resolved
Comment thread tests/numpy/datetime_test.py Resolved
Comment thread arkouda/numpy/numeric.py Resolved
@Bears-R-Us Bears-R-Us deleted a comment from codecov-commenter Jan 12, 2026
Comment thread tests/numpy/datetime_test.py Resolved
Comment thread arkouda/numpy/numeric.py Resolved
Comment thread arkouda/numpy/numeric.py Resolved
@drculhane

Copy link
Copy Markdown
Contributor Author

This could not be rebased, so it's been closed and replaced with PR #5315.

github-merge-queue Bot pushed a commit that referenced this pull request Feb 9, 2026
…" in arctan2 (#5315)

Closes #5132 and #5149.

This takes the place of PR #5204.

- The binops in pdarrayclass.py now give a RuntimeWarning or a Floating
Point Error (or nothing) if / or // cause a divide-by-zero, _depending
on the "divide" setting of ak.errstate_.

- Because the RuntimeWarning surfaced an issue in `arctan2`, I've
rewritten that function somewhat. It now has an "out" parameter matching
numpy, and uses the "where" parameter correctly.

- arctan2 now also accepts bool inputs, which requires special handling.
np.arctan2, if given bool inputs, returns np.float16, which arkouda
doesn't like.

- Most of the original arctan2 function remains as `_arctan2_`, because
(_subjective opinion here_) I think that calling it as a separate
function improves the readability of the code.

- In doing this rewriting, I removed some mypy ignores that are no
longer needed.

- I rewrote the unit tests for `arctan2` to use our newer assert
functions. I think this cleans up that code significantly. In the cases
that use "where," I check both the returned result, and the returned
"out" pdarray, since they should match.

---------

Co-authored-by: drculhane <[email protected]>
ajpotts added a commit that referenced this pull request Feb 11, 2026
Closes #5132.

This takes the place of PR #5204.

- The binops in pdarrayclass.py now give a RuntimeWarning or a Floating
Point Error (or nothing) if / or // cause a divide-by-zero, _depending
on the "divide" setting of ak.errstate_.

- Because the RuntimeWarning surfaced an issue in `arctan2`, I've
rewritten that function somewhat. It now has an "out" parameter matching
numpy, and uses the "where" parameter correctly.

NOTE: the arctan2 and test_arctan2 changes have been removed. They'll
come back in another PR.

- In doing this rewriting, I removed some mypy ignores that are no
longer needed.

Co-authored-by: drculhane <[email protected]>
Co-authored-by: Amanda Potts <[email protected]>
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.

ak.arctan2 uses the "where" parameter incorrectly. floor division by zero doesn't match numpy

2 participants