Skip to content

Commit 8ce7687

Browse files
committed
Merge pull request #5747 from jreback/empty_frame3
API/REGRESS: partial revert of f8b6208 (GH5720,GH5744)
2 parents f8b6208 + 858d114 commit 8ce7687

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

pandas/core/frame.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1916,10 +1916,11 @@ def _ensure_valid_index(self, value):
19161916
'Series')
19171917
self._data.set_axis(1, value.index.copy(), check_axis=False)
19181918

1919+
# we are a scalar
1920+
# noop
19191921
else:
1920-
raise ValueError('Cannot set a frame with no defined index '
1921-
'and a value that cannot be converted to a '
1922-
'Series')
1922+
1923+
pass
19231924

19241925
def _set_item(self, key, value):
19251926
"""

pandas/tests/test_indexing.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1778,14 +1778,12 @@ def f():
17781778
# don't create rows when empty
17791779
df = DataFrame({"A": [1, 2, 3], "B": [1.2, 4.2, 5.2]})
17801780
y = df[df.A > 5]
1781-
def f():
1782-
y['New'] = np.nan
1783-
self.assertRaises(ValueError, f)
1781+
y['New'] = np.nan
1782+
assert_frame_equal(y,DataFrame(columns=['A','B','New']))
17841783

17851784
df = DataFrame(columns=['a', 'b', 'c c'])
1786-
def f():
1787-
df['d'] = 3
1788-
self.assertRaises(ValueError, f)
1785+
df['d'] = 3
1786+
assert_frame_equal(df,DataFrame(columns=['a','b','c c','d']))
17891787
assert_series_equal(df['c c'],Series(name='c c',dtype=object))
17901788

17911789
# reindex columns is ok

0 commit comments

Comments
 (0)