Skip to content

BUG: is_unique fails when using float128 indexes, since pandas 2.0 #59826

Open
@morotti

Description

@morotti

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

Hello,

Noticed a regression when using float128. Code to reproduce the bug below.

  • It works fine on pandas 1.0.5 + 1.5.3
  • It fails on pandas 2.0.3 + 2.1.4 + 2.2.2

is_unique is failing on first call, then giving an incorrect result on later calls.
is_monotonic_increasing gives an incorrect result.

I think we have two bugs at play here.

  1. is_unique is obviously bugged, failing raising an exception.
  2. is_monotonic_increasing depends on is_unique and they are both cached. There may be a bug in the caching code not handling is_unique raising an exception.
import pandas as pd
idx = pd.Index([2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0], dtype='float128')
print("pandas version? ", pd.__version__)
print("monotonic? ", idx.is_monotonic_increasing)
print("unique? ", idx.is_unique)

Issue Description

First call of is_unique failing on pandas 2.2.2

# python debug_float128.py

pandas version?  2.2.2
monotonic?  False

Traceback (most recent call last):
  File "/users/is/rmorotti/debug_float128.py", line 5, in <module>
    print("unique? ", idx.is_unique)
                      ^^^^^^^^^^^^^
  File "properties.pyx", line 36, in pandas._libs.properties.CachedProperty.__get__
  File "/turbo/rmorotti/pyenvs/debugpandas/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 2346, in is_unique
    return self._engine.is_unique
           ^^^^^^^^^^^^^^^^^^^^^^
  File "index.pyx", line 266, in pandas._libs.index.IndexEngine.is_unique.__get__
  File "index.pyx", line 271, in pandas._libs.index.IndexEngine._do_unique_check
  File "index.pyx", line 333, in pandas._libs.index.IndexEngine._ensure_mapping_populated
  File "pandas/_libs/hashtable_class_helper.pxi", line 7105, in pandas._libs.hashtable.PyObjectHashTable.map_locations
ValueError: Buffer dtype mismatch, expected 'Python object' but got 'long double'

Expected Behavior

Works fine on pandas 1.5.3

# python debug_float128.py

pandas version?  1.5.3
monotonic?  True
unique?  True

Installed Versions

bug since pandas 2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexRelated to the Index class or subclassesNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions