Skip to content

BUG: Empty dataframe with .astype raises Exception #35457

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
2 of 3 tasks
eliasmistler opened this issue Jul 29, 2020 · 1 comment
Closed
2 of 3 tasks

BUG: Empty dataframe with .astype raises Exception #35457

eliasmistler opened this issue Jul 29, 2020 · 1 comment
Labels
Bug Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@eliasmistler
Copy link

  • 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 pandas as pd

pd.DataFrame([]).astype({})

Problem description

I've got some generic code handling a large number of DataFrames, and among other things, forcing the data types of certain columns. Some of these DataFrames can be empty - however, that should not stop the calculations.

My expectation would be that I can run any operation that is conceptually a nop on a DataFrame without causing an issue. In this case, I can run .astype({}) on any DataFrame (empty or not) that has columns - so far, so good. However, on a DataFrame with 0 columns, the function fails with a ValueError: "No objects to concatenate"

Expected Output

Empty DataFrame

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Darwin
OS-release : 19.5.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_GB.UTF-8
pandas : 1.0.4
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 19.3.1
setuptools : 42.0.2
Cython : None
pytest : 5.4.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.15.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.4.3
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.17
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@eliasmistler eliasmistler added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 29, 2020
@simonjayhawkins
Copy link
Member

Thanks @eliasmistler for the report. I believe this is a duplicate of #33113 so closing. This is fixed in pandas 1.1.0 (released yesterday)

>>> pd.__version__
'1.2.0.dev0+5.g2c3fa22c0'
>>>
>>> pd.DataFrame([]).astype({})
Empty DataFrame
Columns: []
Index: []
>>>

@simonjayhawkins simonjayhawkins added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Duplicate Report Duplicate issue or pull request and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 29, 2020
@simonjayhawkins simonjayhawkins added this to the No action milestone Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants