diff --git a/doc/source/whatsnew/v0.16.1.txt b/doc/source/whatsnew/v0.16.1.txt index 659aa6786b366..8bd2939e2c805 100755 --- a/doc/source/whatsnew/v0.16.1.txt +++ b/doc/source/whatsnew/v0.16.1.txt @@ -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`) diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 4d0f8394fbd2a..7cc7bc390bcbb 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -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 diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index c7c35e63d3d91..bcba891ee7e9d 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -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']