Skip to content

BUG: DataFrame creates an object-dtype array for extension type scalars in dictionaries #35965

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

Closed
3 tasks done
justinessert opened this issue Aug 28, 2020 · 2 comments · Fixed by #35966
Closed
3 tasks done
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Period Period data type
Milestone

Comments

@justinessert
Copy link
Contributor

  • 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

df = pd.DataFrame({
    'a': [pd.Period('2020-01')],
    'b': pd.Period('2020-01')
})

df.dtypes

Problem description

In the example above, column a will be correctly created as a period[m] column, but column b will be an object type. This is similar to an issue 34832, but for a different DF instantiation method.

Expected Output

These two columns should have identical types. They should both be type period[m].

Output of pd.show_versions()

INSTALLED VERSIONS

commit : c413df6
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.2.0.dev0+173.gc413df6d6.dirty
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
fsspec : 0.7.4
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

@justinessert justinessert added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 28, 2020
@dsaxton dsaxton removed the Needs Triage Issue that has not been reviewed by a pandas team member label Aug 29, 2020
@dsaxton
Copy link
Member

dsaxton commented Aug 30, 2020

Also when some array-likes are passed in directly we get object dtype:

In [1]: import numpy as np

In [2]: import pandas as pd

In [3]: pd.__version__
Out[3]: '1.1.1'

In [4]: pd.DataFrame(3 * [pd.Period("2020-01")]).dtypes
Out[4]:
0    object
dtype: object

In [5]: pd.DataFrame(np.array(3 * [pd.Period("2020-01")])).dtypes
Out[5]:
0    object
dtype: object

@justinessert
Copy link
Contributor Author

Notably, a 2d array does work as expected though

In [1]: pd.DataFrame([[pd.Period('2020-01'), 1], [pd.Period('2020-01'), 1]]).dtypes
Out [1]:
0    period[M]
1        int64
dtype: object

@jreback jreback added Constructors Series/DataFrame/Index/pd.array Constructors Period Period data type labels Sep 1, 2020
@jreback jreback added this to the 1.2 milestone Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants