Skip to content

Empty dataframe corrupted by column add (0.13rc1) #5720

@gdraps

Description

@gdraps

Noticed the following difference in behavior between 0.12 and 0.13rc1 when adding a column to an empty dataframe. Obviously, a weird case, and can be worked around easily.

df = pd.DataFrame({"A": [1, 2, 3], "B": [1.2, 4.2, 5.2]})
y = df[df.A > 5]
y['New'] = np.nan
print y
print y.values

 

(pandas-0.12)$ python test.py 
Empty DataFrame
Columns: [A, B, New]
Index: []
[]

 

(pandas-master)$ python test.py 
     A    B  New
0  NaN  NaN  NaN

[1 rows x 3 columns]
Traceback (most recent call last):
  File "do_fail.py", line 8, in <module>
    print y.values
  File "/home/gmd/ENV/pandas-master-2/lib/python2.7/site-packages/pandas-0.13.0rc1_82_g66934c2-py2.7-linux-i686.egg/pandas/core/generic.py", line 1705, in values
    return self.as_matrix()
  File "/home/gmd/ENV/pandas-master-2/lib/python2.7/site-packages/pandas-0.13.0rc1_82_g66934c2-py2.7-linux-i686.egg/pandas/core/generic.py", line 1697, in as_matrix
    self._consolidate_inplace()
  File "/home/gmd/ENV/pandas-master-2/lib/python2.7/site-packages/pandas-0.13.0rc1_82_g66934c2-py2.7-linux-i686.egg/pandas/core/generic.py", line 1622, in _consolidate_inplace
    self._data = self._protect_consolidate(f)
  File "/home/gmd/ENV/pandas-master-2/lib/python2.7/site-packages/pandas-0.13.0rc1_82_g66934c2-py2.7-linux-i686.egg/pandas/core/generic.py", line 1660, in _protect_consolidate
    result = f()
  File "/home/gmd/ENV/pandas-master-2/lib/python2.7/site-packages/pandas-0.13.0rc1_82_g66934c2-py2.7-linux-i686.egg/pandas/core/generic.py", line 1621, in <lambda>
    f = lambda: self._data.consolidate()
  File "/home/gmd/ENV/pandas-master-2/lib/python2.7/site-packages/pandas-0.13.0rc1_82_g66934c2-py2.7-linux-i686.egg/pandas/core/internals.py", line 2727, in consolidate
    bm = self.__class__(self.blocks, self.axes)
  File "/home/gmd/ENV/pandas-master-2/lib/python2.7/site-packages/pandas-0.13.0rc1_82_g66934c2-py2.7-linux-i686.egg/pandas/core/internals.py", line 1945, in __init__
    self._verify_integrity()
  File "/home/gmd/ENV/pandas-master-2/lib/python2.7/site-packages/pandas-0.13.0rc1_82_g66934c2-py2.7-linux-i686.egg/pandas/core/internals.py", line 2227, in _verify_integrity
    tot_items, block.values.shape[1:], self.axes)
  File "/home/gmd/ENV/pandas-master-2/lib/python2.7/site-packages/pandas-0.13.0rc1_82_g66934c2-py2.7-linux-i686.egg/pandas/core/internals.py", line 3561, in construction_error
    tuple(map(int, [len(ax) for ax in axes]))))
ValueError: Shape of passed values is (3, 0), indices imply (3, 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignBugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions