Skip to content

BUG: don't use partial setting with scalars (GH5720) #5723

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
Dec 17, 2013
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 @@ -246,7 +246,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:`2578`, :issue:`5226`, :issue:`5632`, :issue:`5720`)
- 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
19 changes: 10 additions & 9 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,16 +1904,17 @@ def _ensure_valid_index(self, value):
if not len(self.index):

# GH5632, make sure that we are a Series convertible
try:
value = Series(value)
except:
pass
if is_list_like(value):
try:
value = Series(value)
except:
pass

if not isinstance(value, Series):
raise ValueError('Cannot set a frame with no defined index '
'and a value that cannot be converted to a '
'Series')
self._data.set_axis(1, value.index.copy(), check_axis=False)
if not isinstance(value, Series):
raise ValueError('Cannot set a frame with no defined index '
'and a value that cannot be converted to a '
'Series')
self._data.set_axis(1, value.index.copy(), check_axis=False)

def _set_item(self, key, value):
"""
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 @@ -1730,6 +1730,14 @@ def f():
str(df)
assert_frame_equal(df,expected)

# GH5720
# 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 test_cache_updating(self):
# GH 4939, make sure to update the cache on setitem

Expand Down