-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: use cmath to test complex number equality in pandas._testing #36580
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
Conversation
pandas/_libs/testing.pyx
Outdated
cdef bint is_comparable_as_number(obj): | ||
return isinstance(obj, NUMERIC_TYPES) | ||
|
||
|
||
cdef bint is_comparable_as_complex_number(obj): | ||
return isinstance(obj, COMPLEX_NUMERIC_TYPES) |
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.
we have lib.is_complex for this
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.
Thanks! Switched to using that
Travis failure looks unrelated |
# inf comparison | ||
return True | ||
|
||
if not cmath.isclose(a, b, rel_tol=rtol, abs_tol=atol): |
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.
if not cmath.isclose(a, b, rel_tol=rtol, abs_tol=atol): | |
if cmath.isclose(a, b, rel_tol=rtol, abs_tol=atol): |
I think should just test for True here and return accordingly, otherwise let fall to the standard assertionerror, unless there is a reason for things to be different here?
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.
I copied what we do for reals, where we cite the rtol
and atol
if the comparison fails:
pandas/pandas/_libs/testing.pyx
Lines 208 to 210 in da1c6de
if not math.isclose(fa, fb, rel_tol=rtol, abs_tol=atol): | |
assert False, (f"expected {fb:.5f} but got {fa:.5f}, " | |
f"with rtol={rtol}, atol={atol}") |
whereas the message at the bottom is just:
pandas/pandas/_libs/testing.pyx
Line 213 in da1c6de
raise AssertionError(f"{a} != {b}") |
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.
can you add a whatsnew note, bug fixes in numeric for 1.2 (and @WillAyd comments); ping on green.
Green barring unrelated doctest failure:
|
46e4579
to
4e9fa93
Compare
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.
lgtm
Thanks @arw2019 |
Thanks @WillAyd @jreback @jbrockmendel for reviewing! |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Adds
cmath
-based equality testing for complex numeric types (complex
,np.complex64
andnp.complex128
)