Open
Description
-
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.
noticed while working on #30858
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
This returns an error:
>>> import pandas as pd
>>> pd.DataFrame(pd.Series([]), columns=[])
<stdin>:1: DeprecationWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
Traceback (most recent call last):
File "/home/marco/pandas-dev/pandas/core/internals/managers.py", line 1613, in create_block_manager_from_blocks
make_block(values=blocks[0], placement=slice(0, len(axes[0])))
File "/home/marco/pandas-dev/pandas/core/internals/blocks.py", line 2728, in make_block
return klass(values, ndim=ndim, placement=placement)
File "/home/marco/pandas-dev/pandas/core/internals/blocks.py", line 121, in __init__
raise ValueError(
ValueError: Wrong number of items passed 1, placement implies 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/marco/pandas-dev/pandas/core/frame.py", line 488, in __init__
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
File "/home/marco/pandas-dev/pandas/core/internals/construction.py", line 234, in init_ndarray
return create_block_manager_from_blocks(block_values, [columns, index])
File "/home/marco/pandas-dev/pandas/core/internals/managers.py", line 1623, in create_block_manager_from_blocks
raise construction_error(tot_items, blocks[0].shape[1:], axes, e)
ValueError: Empty data passed with indices specified.
But this doesn't:
>>> pd.DataFrame([], columns=[])
Empty DataFrame
Columns: []
Index: []
#### Problem description
[this should explain **why** the current behaviour is a problem and why the expected output is a better solution]
#### Expected Output
Empty DataFrame
Columns: []
Index: []
#### Output of ``pd.show_versions()``
<details>
INSTALLED VERSIONS
------------------
commit : 6a6faf596bc1e3bf4078d4837f654d0f2f754820
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-37-generic
Version : #41-Ubuntu SMP Wed Jun 3 18:57:02 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.1.0.dev0+1944.g6a6faf596
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.1
sphinx : 3.1.1
blosc : None
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.1
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.48.0
</details>