Skip to content

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

Closed
@unutbu

Description

@unutbu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsDeprecateFunctionality to remove in pandas

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions