Skip to content

ak.arctan2 uses the "where" parameter incorrectly. #5149

Open

Description

@drculhane

Update:

This is true of every function that uses "where" in arkouda/numpy/numeric.py.

The numpy counterparts of all of these functions only use "where" if "out" is also used. We don't have "out" in any of our functions.


ak.arctan2 uses "where" incorrectly.

np.arctan2 only uses "where" if the "out" parameter is also specified. If "where" is True, it puts arctan2(a,b) in "out." If "where" is False, it leaves the "out" parameter unchanged. So, for example:

a = np.arange(17)
b = np.arange(17) - 8
c = np.ones(17)
np.arctan2(b,a,where=False)
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

Instead, ak.arctan2 returns arctan2(a,b) when "where" is True, and a/b when "where" is False.

za = ak.array(a)
zb = ak.array(b)
ak.arctan2(zb,za,where=False).to_ndarray()
array([       -inf, -7.        , -3.        , -1.66666667, -1.        ,
       -0.6       , -0.33333333, -0.14285714,  0.        ,  0.11111111,
        0.2       ,  0.27272727,  0.33333333,  0.38461538,  0.42857143,
        0.46666667,  0.5       ])

This can cause divide-by-zeros. In an upcoming PR where we generate RuntimeWarnings on divide-by-zero, this causes test_arctan2 to fail, because both arctan2 and test_arctan2 divide by denom (which can include zeros) when where is False.

I suggest eliminating the "where" parameter from ak.arctan2, since it depends on "out," and we don't incorporate the "out" parameter anywhere in arkouda that I know of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions