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
2 changes: 1 addition & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ API Changes
(:issue:`4390`)
- allow ``ix/loc`` for Series/DataFrame/Panel to set on any axis even when
the single-key is not currently contained in the index for that axis
(:issue:`2578`, :issue:`5226`, :issue:`5632`, :issue:`5720`)
(:issue:`2578`, :issue:`5226`, :issue:`5632`, :issue:`5720`, :issue:`5744`)
- Default export for ``to_clipboard`` is now csv with a sep of `\t` for
compat (:issue:`3368`)
- ``at`` now will enlarge the object inplace (and return the same)
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,11 @@ def _ensure_valid_index(self, value):
'Series')
self._data.set_axis(1, value.index.copy(), check_axis=False)

else:
raise ValueError('Cannot set a frame with no defined index '
'and a value that cannot be converted to a '
'Series')

def _set_item(self, key, value):
"""
Add series to DataFrame in specified column.
Expand Down
21 changes: 17 additions & 4 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,13 +1753,26 @@ def f():
str(df)
assert_frame_equal(df,expected)

# GH5720
# GH5720, GH5744
# don't create rows when empty
df = DataFrame({"A": [1, 2, 3], "B": [1.2, 4.2, 5.2]})
y = df[df.A > 5]
y['New'] = np.nan
expected = DataFrame(columns=['A','B','New'])
assert_frame_equal(y, expected)
def f():
y['New'] = np.nan
self.assertRaises(ValueError, f)

df = DataFrame(columns=['a', 'b', 'c c'])
def f():
df['d'] = 3
self.assertRaises(ValueError, f)
assert_series_equal(df['c c'],Series(name='c c',dtype=object))

# reindex columns is ok
df = DataFrame({"A": [1, 2, 3], "B": [1.2, 4.2, 5.2]})
y = df[df.A > 5]
result = y.reindex(columns=['A','B','C'])
expected = DataFrame(columns=['A','B','C'])
assert_frame_equal(result,expected)

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