From 7d58949ee5cf910ece0374a10046833ea6c23d6d Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Fri, 27 Jun 2014 09:30:09 -0400 Subject: [PATCH] BUG: bug in float64index assignment with a non scalar indexer --- doc/source/v0.14.1.txt | 2 ++ pandas/core/index.py | 2 +- pandas/tests/test_indexing.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/source/v0.14.1.txt b/doc/source/v0.14.1.txt index 45a5d55ca047d..e7eaf49265fe5 100644 --- a/doc/source/v0.14.1.txt +++ b/doc/source/v0.14.1.txt @@ -262,3 +262,5 @@ Bug Fixes - Bug in non-monotonic ``Index.union`` may preserve ``name`` incorrectly (:issue:`7458`) - Bug in ``DatetimeIndex.intersection`` doesn't preserve timezone (:issue:`4690`) + +- Bug in ``Float64Index`` assignment with a non scalar indexer (:issue:`7586`) diff --git a/pandas/core/index.py b/pandas/core/index.py index 030f902eb13ce..2138ecfa5281f 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -2074,7 +2074,7 @@ def __contains__(self, other): def get_loc(self, key): try: - if np.isnan(key): + if np.all(np.isnan(key)): try: return self._nan_idxs.item() except ValueError: diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 9b72d2f92182f..1a4da63a135a2 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -3684,6 +3684,18 @@ def test_duplicate_ix_returns_series(self): e = df.loc[0.2, 'a'] tm.assert_series_equal(r, e) + def test_float_index_non_scalar_assignment(self): + df = DataFrame({'a': [1,2,3], 'b': [3,4,5]},index=[1.,2.,3.]) + df.loc[df.index[:2]] = 1 + expected = DataFrame({'a':[1,1,3],'b':[1,1,5]},index=df.index) + tm.assert_frame_equal(expected, df) + + df = DataFrame({'a': [1,2,3], 'b': [3,4,5]},index=[1.,2.,3.]) + df2 = df.copy() + df.loc[df.index] = df.loc[df.index] + tm.assert_frame_equal(df,df2) + + if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],