Skip to content

deepcopy failure on empty dataframes with non-empty column set (numpy 1.12 compatibility) #15370

Closed
@bmcfee

Description

@bmcfee

Code Sample, a copy-pastable example if possible

# Your code here
import pandas as pd
import copy

# This one works
df = pd.DataFrame(data=[], index=[])
df_copy = copy.deepcopy(df)

# This one fails
df2 = pd.DataFrame(data=[], index=[], columns=['a'])
df2_copy = copy.deepcopy(df2)

Problem description

This only occurs with numpy 1.12 (and, presumably above): when deepcopying an empty dataframe with a non-empty column set, it fails with the following:

ValueError: Iteration of zero-sized operands is not enabled

If the column set is also empty, everything works as expected.

On older numpy versions (1.11), it also works as expected.

Expected Output

Not failing.

Output of pd.show_versions()

# Paste the output here pd.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.4.0.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-62-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 32.3.1.post20170108
Cython: 0.25.2
numpy: 1.12.0
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
boto: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions