Skip to content

BUG: nan-objects lookup fails in Python3.10  #41953

Closed
@realead

Description

@realead
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Due to this change in CPython: python/cpython@a07da09

the following assumption is no longer true:

// For PyObject_Hash holds:
// hash(0.0) == 0 == hash(-0.0)
// hash(X) == 0 if X is a NaN-value
// so it is OK to use it directly for doubles
Py_hash_t hash = PyObject_Hash(key);

Here is a failing example:

_____________________ TestIsin.test_different_nan_objects ______________________

self = <pandas.tests.test_algos.TestIsin object at 0x7f9ba1fe7250>

    def test_different_nan_objects(self):
        # GH 22119
        comps = np.array(["nan", np.nan * 1j, float("nan")], dtype=object)
        vals = np.array([float("nan")], dtype=object)
        expected = np.array([False, False, True])
        result = algos.isin(comps, vals)
>       tm.assert_numpy_array_equal(expected, result)

pandas/tests/test_algos.py:1039: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

left = array([False, False,  True]), right = array([False, False, False])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions