Skip to content

BUG: Bug in creating an empty DataFrame, copying, then assigning (GH5932) #5935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------
Expand Down
7 changes: 5 additions & 2 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down