diff --git a/doc/source/release.rst b/doc/source/release.rst index 6967c096ae90a..9ab175c07f169 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -89,6 +89,7 @@ Bug Fixes - Bug in idxmin/max with object dtypes (:issue:`5914`) - Bug in ``BusinessDay`` when adding n days to a date not on offset when n>5 and n%5==0 (:issue:`5890`) - Bug in assigning to chained series with a series via ix (:issue:`5928`) + - Bug in creating an empty DataFrame, copying, then assigning (:issue:`5932`) pandas 0.13.0 ------------- diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 7f49f7c1993bd..5c77930a206b7 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -1961,8 +1961,11 @@ def make_empty(self, axes=None): ] # preserve dtype if possible - dtype = self.dtype if self.ndim == 1 else object - return self.__class__(np.array([], dtype=dtype), axes) + if self.ndim == 1: + blocks = np.array([], dtype=self.dtype) + else: + blocks = [] + return self.__class__(blocks, axes) def __nonzero__(self): return True diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index a420dcc7b68e4..1a7359eed45fc 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -1843,6 +1843,14 @@ def f(): df = DataFrame(Series(name='foo')) assert_frame_equal(df, DataFrame({ 'foo' : Series() })) + # GH 5932 + # copy on empty with assignment fails + df = DataFrame(index=[0]) + df = df.copy() + df['a'] = 0 + expected = DataFrame(0,index=[0],columns=['a']) + assert_frame_equal(df, expected) + def test_cache_updating(self): # GH 4939, make sure to update the cache on setitem