Skip to content

Deprecation/FutureWarnings raised by == on NumPy arrays in NumPy version1.9 #8537

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
unutbu opened this issue Oct 11, 2014 · 4 comments · Fixed by #11356
Closed

Deprecation/FutureWarnings raised by == on NumPy arrays in NumPy version1.9 #8537

unutbu opened this issue Oct 11, 2014 · 4 comments · Fixed by #11356
Labels
Compat pandas objects compatability with Numpy or Python functions Deprecate Functionality to remove in pandas
Milestone

Comments

@unutbu
Copy link
Contributor

unutbu commented Oct 11, 2014

This continues a discussion started at the end of GH 8512

Summary: NumPy is changing the behavior of ==. It no longer checks for is relationships between elements. Therefore,

In older versions of NumPy:

array([nan], dtype=object) == array([nan], dtype=object)
array([ True], dtype=bool)

In future NumPy, I think this will happen:

array([nan], dtype=object) == array([nan], dtype=object)
array([ False], dtype=bool)

In current NumPy version 1.9, a DeprecationWarning or FutureWarning is issued.

One place where this issue affects Pandas is

nosetests -v pandas/tests/test_series.py:TestSeries.test_replace

The problem originates in internals.py/_possibly_compare which is called like this:

_possibly_compare(np.array([1, np.nan], dtype='O'), 'foo', operater.eq)
_possibly_compare(np.array(['2000-01-02T19:00'], dtype='datetime64[ns]'), 1, operater.eq)

Both of these raise DeprecationWarnings.

a is always an array, b is a scalar. AFAICT, the intent of
_possibly_compare is to return a boolean mask where elements in a equal b.
Since we want a boolean mask, array_equivalent is not a help here since that
just returns a single bool.

@unutbu
Copy link
Contributor Author

unutbu commented Oct 11, 2014

Above, a and b refer to _possibly_compare(a, b, operator.eq)

@jreback jreback added the Deprecate Functionality to remove in pandas label Oct 11, 2014
@jreback jreback added this to the 0.15.1 milestone Oct 11, 2014
@unutbu
Copy link
Contributor Author

unutbu commented Oct 14, 2014

@jreback: I think this problem would be a lot easier to fix if in future versions of NumPy, ndarray.__eq__ would simply return False instead of TypeError for things like

np.array(['2000-01-02T19:00'], dtype='<M8[ns]') == 1

False is what it returns now, so I think the majority of those DeprecationWarnings would be moot.

Meanwhile, the FutureWarnings (I think -- I should check this some more --) only occur when comparing NaNs in object arrays. We (hopefully) already address this issue with things like isnull and array_equivalent, so again the FutureWarnings should be moot.

What do you think? Do you think we should ask the NumPy developers to change the TypeErrors to False?

@jreback
Copy link
Contributor

jreback commented Oct 14, 2014

why don't u post a numpy issue and see why they are doing it this way

I agree it would be more consistent to simply return FAlse

@unutbu
Copy link
Contributor Author

unutbu commented Oct 15, 2014

@jreback: NumPy issue: numpy/numpy#5188 (comment)

@jreback jreback modified the milestones: 0.15.2, 0.16.0 Nov 24, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jreback jreback added Compat pandas objects compatability with Numpy or Python functions Prio-medium labels Oct 16, 2015
@jreback jreback modified the milestones: 0.17.1, Next Major Release Oct 16, 2015
jreback added a commit that referenced this issue Oct 18, 2015
WIP: avoid some numpy warnings #8537
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Deprecate Functionality to remove in pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants