Skip to content
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 @@ -174,6 +174,7 @@ Bug Fixes
being thrown away (:issue:`6148`).
- Bug in ``HDFStore`` on appending a dataframe with multi-indexed columns to
an existing table (:issue:`6167`)
- Consistency with dtypes in setting an empty DataFrame (:issue:`6171`)

pandas 0.13.0
-------------
Expand Down
13 changes: 12 additions & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,18 @@ def set(self, item, value, check=False):
return
except:
pass
self.values[loc] = value
try:
self.values[loc] = value
except (ValueError):

# broadcasting error
# see GH6171
new_shape = list(value.shape)
new_shape[0] = len(self.items)
self.values = np.empty(tuple(new_shape),dtype=self.dtype)
self.values.fill(np.nan)
self.values[loc] = value


def _maybe_downcast(self, blocks, downcast=None):

Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,23 @@ def f():
expected = DataFrame(0,index=[0],columns=['a'])
assert_frame_equal(df, expected)

# GH 6171
# consistency on empty frames
df = DataFrame(columns=['x', 'y'])
df['x'] = [1, 2]
expected = DataFrame(dict(x = [1,2], y = [np.nan,np.nan]))
assert_frame_equal(df, expected, check_dtype=False)

df = DataFrame(columns=['x', 'y'])
df['x'] = ['1', '2']
expected = DataFrame(dict(x = ['1','2'], y = [np.nan,np.nan]),dtype=object)
assert_frame_equal(df, expected)

df = DataFrame(columns=['x', 'y'])
df.loc[0, 'x'] = 1
expected = DataFrame(dict(x = [1], y = [np.nan]))
assert_frame_equal(df, expected, check_dtype=False)

def test_cache_updating(self):
# GH 4939, make sure to update the cache on setitem

Expand Down