Skip to content

BUG: nanops._maybe_null_out doesn't work with complex numbers #7353

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

Closed
toddrjen opened this issue Jun 5, 2014 · 3 comments · Fixed by #7428
Closed

BUG: nanops._maybe_null_out doesn't work with complex numbers #7353

toddrjen opened this issue Jun 5, 2014 · 3 comments · Fixed by #7428
Labels
Bug Internals Related to non-user accessible pandas implementation Numeric Operations Arithmetic, Comparison, and Logical operations Testing pandas testing functions or related to the test suite
Milestone

Comments

@toddrjen
Copy link
Contributor

toddrjen commented Jun 5, 2014

A number of nanops functions rely on the private internal function nanops._maybe_null_out. These include nansum, nanmin, nanmax, and nanprod. All of these, in principle, should work with arrays with a complex dtype. However, due to a bug in _maybe_null_out, they convert the array to a float under certain situations, resulting in erroneous results. The easiest way to trigger this is to have a complex array where all the imaginary values are nan, and make axis argument something other than None.

>>> from pandas.core import nanops
>>> import bottleneck
>>> import numpy as np
>>> nanops._USE_BOTTLENECK = False
>>> 
>>> val = np.tile(1, (11, 7)) + np.tile(np.nan*1j, (11, 7))
>>> 
>>> bottleneck.nansum(val, axis=0)
array([ nan+0.j,  nan+0.j,  nan+0.j,  nan+0.j,  nan+0.j,  nan+0.j,  nan+0.j])
>>> nanops.nansum(val, axis=0)
array([ nan,  nan,  nan,  nan,  nan,  nan,  nan])
>>> bottleneck.nansum(val, axis=0).dtype
dtype('complex128')
>>> nanops.nansum(val, axis=0).dtype
dtype('float64')
@jreback jreback added this to the 0.15.0 milestone Jun 5, 2014
@jreback jreback modified the milestones: 0.14.1, 0.15.0 Jun 5, 2014
@toddrjen toddrjen changed the title BUG: nanops. _maybe_null_out doesn't work with complex numbers BUG: nanops._maybe_null_out doesn't work with complex numbers Jun 11, 2014
jreback added a commit that referenced this issue Jun 12, 2014
make nanops._maybe_null_out work with complex numbers ( issue #7353 )
@jreback
Copy link
Contributor

jreback commented Jun 12, 2014

this is failing on numpy 1.9-dev: https://travis-ci.org/pydata/pandas/jobs/27401353

might be spurious or maybe the comparison needs to have less precision...

pls lmk

@toddrjen
Copy link
Contributor Author

I can submit another pull request later or include a precision change in
the current one. The problem only appears to occur with complex numbers.
I encountered it before with another function and fixed it there, it seems
to depend on the random numbers chosen.

On Thu, Jun 12, 2014 at 3:38 PM, jreback [email protected] wrote:

this is failing on numpy 1.9-dev:
https://travis-ci.org/pydata/pandas/jobs/27401353

might be spurious or maybe the comparison needs to have less precision...

pls lmk


Reply to this email directly or view it on GitHub
#7353 (comment).

@jreback
Copy link
Contributor

jreback commented Jun 12, 2014

just modify the latest PR to fix;

you could set np.random.seed(123456) or whatever in the setUp for the nanops tests
and/or use less precision (maybe just for complex)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Internals Related to non-user accessible pandas implementation Numeric Operations Arithmetic, Comparison, and Logical operations Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants