Skip to content

Commit a8c1d5d

Browse files
committed
Merge pull request #9934 from evanpw/issue_9596
BUG: Exception when setting an empty range using DataFrame.loc
2 parents 529cd3d + a21f2ce commit a8c1d5d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v0.16.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,4 @@ Bug Fixes
161161
- 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`)
162162

163163
- Fixed latex output for multi-indexed dataframes (:issue:`9778`)
164+
- Bug causing an exception when setting an empty range using ``DataFrame.loc`` (:issue:`9596`)

pandas/core/internals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def _is_empty_indexer(indexer):
582582
if arr_value.ndim == 1:
583583
if not isinstance(indexer, tuple):
584584
indexer = tuple([indexer])
585-
return all([ isinstance(idx, np.ndarray) and len(idx) == 0 for idx in indexer ])
585+
return any(isinstance(idx, np.ndarray) and len(idx) == 0 for idx in indexer)
586586
return False
587587

588588
# empty indexers

pandas/tests/test_frame.py

+10
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,16 @@ def test_setitem_None(self):
784784
assert_series_equal(self.frame[None], self.frame['A'])
785785
repr(self.frame)
786786

787+
def test_setitem_empty(self):
788+
# GH 9596
789+
df = pd.DataFrame({'a': ['1', '2', '3'],
790+
'b': ['11', '22', '33'],
791+
'c': ['111', '222', '333']})
792+
793+
result = df.copy()
794+
result.loc[result.b.isnull(), 'a'] = result.a
795+
assert_frame_equal(result, df)
796+
787797
def test_delitem_corner(self):
788798
f = self.frame.copy()
789799
del f['D']

0 commit comments

Comments
 (0)