hgrecco / pint-pandas

Pandas support for pint
Other
166 stars 40 forks source link

Incompatible with pandas 2.1.0: `AttributeError: module 'pandas.core.dtypes.dtypes' has no attribute 'PandasDtype'` #199

Closed burnpanck closed 10 months ago

burnpanck commented 10 months ago

It appears that something moved inside pandas recently, and now pint_pandas cannot be imported anymore.

This is with pandas 2.1.0 (released today) and pint_pandas 0.4.0.

Full traceback:


import pint_pandas
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 1
----> 1 import pint_pandas

File ~/.pyenv/versions/3.11.3/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pint_pandas/__init__.py:3
      1 import pprint
----> 3 from .pint_array import PintArray, PintType
      5 try:
      6     from importlib.metadata import version

File ~/.pyenv/versions/3.11.3/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pint_pandas/pint_array.py:198
    178         """
    179         Return a string representation for this object.
    180 
    181         Invoked by unicode(df) in py2 only. Yields a Unicode String in both
    182         py2/py3.
    183         """
    185         return self.name
    188 dtypemap = {
    189     int: pd.Int64Dtype(),
    190     np.int64: pd.Int64Dtype(),
    191     np.int32: pd.Int32Dtype(),
    192     np.int16: pd.Int16Dtype(),
    193     np.int8: pd.Int8Dtype(),
    194     # np.float128: pd.Float128Dtype(),
    195     float: pd.Float64Dtype(),
    196     np.float64: pd.Float64Dtype(),
    197     np.float32: pd.Float32Dtype(),
--> 198     np.complex128: pd.core.dtypes.dtypes.PandasDtype("complex128"),
    199     np.complex64: pd.core.dtypes.dtypes.PandasDtype("complex64"),
    200     # np.float16: pd.Float16Dtype(),
    201 }
    202 dtypeunmap = {v: k for k, v in dtypemap.items()}
    205 class PintArray(ExtensionArray, ExtensionOpsMixin):

AttributeError: module 'pandas.core.dtypes.dtypes' has no attribute 'PandasDtype'
MichaelTiemannOSC commented 10 months ago

Fixed by https://github.com/hgrecco/pint-pandas/pull/195

andrewgsavage commented 10 months ago

@hgrecco could we get a release to pypi ?

hgrecco commented 10 months ago

@andrewgsavage Congratulations!!! Everything seems to work, please check it on your side and let me know

andrewgsavage commented 10 months ago

Thanks! yes it works for me.