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

BUG: Inconsistent dtypes when constructing empty dataframe with empty list #54021

Closed
3 tasks done
harenbrs opened this issue Jul 6, 2023 · 2 comments
Closed
3 tasks done
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@harenbrs
Copy link

harenbrs commented Jul 6, 2023

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

>>> import pandas as pd
>>> pd.Series([]).dtype
dtype('O')
>>> pd.DataFrame(columns=['a']).dtypes['a']
dtype('O')
>>> pd.DataFrame({'a': pd.Series([])}).dtypes['a']
dtype('O')
>>> pd.DataFrame({'a': []}).dtypes['a']
dtype('float64')  # ??

Issue Description

Above are various ways to instantiate an empty dataframe. There is an inconsistency in that specifying an empty list instead of an empty series results in a dtype of float64 instead of object for that column.

Related:
#17261
#49573

Expected Behavior

A user assuming consistency would expect the result of

pd.DataFrame({'a': []}).dtypes

to be:

a    object

Installed Versions

INSTALLED VERSIONS
------------------
commit           : 1e90f9e3c5371bf65347bc1ea5e9b3cef9dfa189
python           : 3.10.12.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
Version          : 10.0.19045
machine          : AMD64
processor        : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : English_Ireland.1252

pandas           : 2.1.0.dev0+1130.g1e90f9e3c5
numpy            : 2.0.0.dev0+425.g2991c0cb3
pytz             : 2023.3
dateutil         : 2.8.2
setuptools       : 67.8.0
pip              : 23.1.2
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : None
gcsfs            : None
matplotlib       : None
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : None
snappy           : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
zstandard        : None
tzdata           : 2023.3
qtpy             : None
pyqt5            : None
@harenbrs harenbrs added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 6, 2023
@btparrish
Copy link

I am a first time contributor and would like to take this one on

@mroeschke
Copy link
Member

Closing as a duplicate of #56679

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants