Skip to content
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

pd.testing.assert_index_equal fails with check_exact=False #254

Open
vhully opened this issue Nov 6, 2024 · 0 comments
Open

pd.testing.assert_index_equal fails with check_exact=False #254

vhully opened this issue Nov 6, 2024 · 0 comments

Comments

@vhully
Copy link

vhully commented Nov 6, 2024

pd.testing.assert_index_equal fails with pint dtype with check_exact=False. It works with the default check_exact=True.

Code:

import pandas as pd
import pint_pandas

index_1 = index_2 = pd.Index(pd.Series([10, 20], dtype="pint[s]"), name="x")
pd.testing.assert_index_equal(index_1, index_2, check_exact=False)

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[38], [line 5](vscode-notebook-cell:?execution_count=38&line=5)
      [2](vscode-notebook-cell:?execution_count=38&line=2) import pint_pandas
      [4](vscode-notebook-cell:?execution_count=38&line=4) index_1 = index_2 = pd.Index(pd.Series([10, 20], dtype="pint[s]"), name="x")
----> [5](vscode-notebook-cell:?execution_count=38&line=5) pd.testing.assert_index_equal(index_1, index_2, check_exact=False)

    [... skipping hidden 1 frame]

File testing.pyx:55, in pandas._libs.testing.assert_almost_equal()

File testing.pyx:160, in pandas._libs.testing.assert_almost_equal()

File testing.pyx:145, in pandas._libs.testing.assert_almost_equal()

File ~/draft/hdf/__venv__/lib/python3.12/site-packages/pint/facets/numpy/quantity.py:217, in NumpyQuantity.__len__(self)
    [216](https://file+.vscode-resource.vscode-cdn.net/home/vianney/draft/hdf/~/draft/hdf/__venv__/lib/python3.12/site-packages/pint/facets/numpy/quantity.py:216) def __len__(self) -> int:
--> [217](https://file+.vscode-resource.vscode-cdn.net/home/vianney/draft/hdf/~/draft/hdf/__venv__/lib/python3.12/site-packages/pint/facets/numpy/quantity.py:217)     return len(self._magnitude)

TypeError: object of type 'numpy.int64' has no len()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant