Skip to content

DataFrame initialization with an empty DataFrame with dtype #20654

Closed
@HansBouwmeester

Description

@HansBouwmeester

Code

>>> pd.DataFrame(pd.DataFrame())
Empty DataFrame
Columns: []
Index: []

>>> pd.DataFrame([], dtype='object')
Empty DataFrame
Columns: []
Index: []

>>> pd.DataFrame(pd.DataFrame(), dtype='object')
Traceback (most recent call last):

  File "<ipython-input-62-36914d1cfa60>", line 1, in <module>
    pd.DataFrame(pd.DataFrame(), dtype='object')

  File "c:\users\hans\appdata\local\programs\python\python36\lib\site-packages\pandas\core\frame.py", line 328, in __init__
    dtype=dtype, copy=copy)

  File "c:\users\hans\appdata\local\programs\python\python36\lib\site-packages\pandas\core\generic.py", line 175, in _init_mgr
    if len(mgr.blocks) > 1 or mgr.blocks[0].values.dtype != dtype:

IndexError: tuple index out of range

Problem description

Initializing a DataFrame from an empty DataFrame with dtype='object' throws an unexpected exception.

Expected Output

Would expect an empty DataFrame to be created.

#### Output of ``pd.show_versions()`` commit: None python: 3.6.3.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: en LOCALE: None.None

pandas: 0.21.1
pytest: 3.5.0
pip: 9.0.3
setuptools: 38.5.2
Cython: None
numpy: 1.13.3
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.7.1
patsy: None
dateutil: 2.7.0
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    ConstructorsSeries/DataFrame/Index/pd.array ConstructorsNeeds TestsUnit test(s) needed to prevent regressionsgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions