Skip to content

BUG: Exception when setting an empty range using DataFrame.loc #9934

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
Apr 18, 2015
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/whatsnew/v0.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,4 @@ Bug Fixes
- Changed caching in ``AbstractHolidayCalendar`` to be at the instance level rather than at the class level as the latter can result in unexpected behaviour. (:issue:`9552`)

- Fixed latex output for multi-indexed dataframes (:issue:`9778`)
- Bug causing an exception when setting an empty range using ``DataFrame.loc`` (:issue:`9596`)
2 changes: 1 addition & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def _is_empty_indexer(indexer):
if arr_value.ndim == 1:
if not isinstance(indexer, tuple):
indexer = tuple([indexer])
return all([ isinstance(idx, np.ndarray) and len(idx) == 0 for idx in indexer ])
return any(isinstance(idx, np.ndarray) and len(idx) == 0 for idx in indexer)
return False

# empty indexers
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,16 @@ def test_setitem_None(self):
assert_series_equal(self.frame[None], self.frame['A'])
repr(self.frame)

def test_setitem_empty(self):
# GH 9596
df = pd.DataFrame({'a': ['1', '2', '3'],
'b': ['11', '22', '33'],
'c': ['111', '222', '333']})

result = df.copy()
result.loc[result.b.isnull(), 'a'] = result.a
assert_frame_equal(result, df)

def test_delitem_corner(self):
f = self.frame.copy()
del f['D']
Expand Down