Skip to content

BUG: DataFrame construction from EA scalar gives object dtype #34959

Open
@justinessert

Description

@justinessert
  • 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.


Code Sample, a copy-pastable example

import decimal
from pandas.tests.extension.decimal.array import DecimalArray, DecimalDtype

import pandas as pd

df = pd.DataFrame(index=[0,1,2], columns=['a'], data=decimal.Decimal('1'))
df['b'] = decimal.Decimal('1')
df.dtypes

Problem description

Both columns 'a' and 'b' are created as object columns in the above DataFrame, instead of the expected Decimal type (and this happens for all 3rd party extension types). This is unexpected because these 3rd party extended are supported as a data type in pandas, but are not being applied.

This issue was originally reported for 1st party extension types in Issue 34832 and should be fixed (for 1st party extensions) in PR 34875. But work still remains to extend this bug fix to 3rd party extension types.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 291eb2d
python : 3.7.6.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
Version : Darwin Kernel Version 18.7.0: Sun Dec 1 18:59:03 PST 2019; root:xnu-4903.278.19~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.0.dev0+1915.g291eb2d11
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.3.1.post20200616
Cython : 0.29.20
pytest : 5.4.3
hypothesis : 5.16.2
sphinx : 3.1.1
blosc : 1.9.1
feather : None
xlsxwriter : 1.2.9
lxml.etree : 4.5.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.15.0
pandas_datareader: None
bs4 : 4.9.1
bottleneck : 1.3.2
fastparquet : 0.4.0
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : 0.17.1
pytables : None
pyxlsb : None
s3fs : 0.4.2
scipy : 1.4.1
sqlalchemy : 1.3.17
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.15.1
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.50.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsExtensionArrayExtending pandas with custom dtypes or arrays.IndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions