Skip to content

.astype() and Decimal #26731

Closed
Closed
@shadchin

Description

@shadchin

Begin from 0.24.0 next code raise exception

import decimal
import pandas as pd
ser = pd.Series([1, 2])
ser.astype(decimal.Decimal)

Traceback

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/shadchin/t_d/venv/local/lib/python2.7/site-packages/pandas/core/generic.py", line 5691, in astype
    **kwargs)
  File "/home/shadchin/t_d/venv/local/lib/python2.7/site-packages/pandas/core/internals/managers.py", line 531, in astype
    return self.apply('astype', dtype=dtype, **kwargs)
  File "/home/shadchin/t_d/venv/local/lib/python2.7/site-packages/pandas/core/internals/managers.py", line 395, in apply
    applied = getattr(b, f)(**kwargs)
  File "/home/shadchin/t_d/venv/local/lib/python2.7/site-packages/pandas/core/internals/blocks.py", line 534, in astype
    **kwargs)
  File "/home/shadchin/t_d/venv/local/lib/python2.7/site-packages/pandas/core/internals/blocks.py", line 595, in _astype
    dtype = pandas_dtype(dtype)
  File "/home/shadchin/t_d/venv/local/lib/python2.7/site-packages/pandas/core/dtypes/common.py", line 2029, in pandas_dtype
    raise TypeError("dtype '{}' not understood".format(dtype))
TypeError: dtype '<class 'decimal.Decimal'>' not understood

Problem description

This begin from #21160

After was

npdtype = np.dtype(dtype)

Now
dtype = pandas_dtype(dtype)

pandas_dtype() does not understand decimal.Decimal

Is it expected behavior or regress?

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.101-26
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.4
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions