Skip to content

Commit 732a2e7

Browse files
committed
Merge pull request #7587 from cpcloud/float64index-assign-7586
BUG: bug in float64index assignment with a non scalar indexer
2 parents f8b101c + 7d58949 commit 732a2e7

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

doc/source/v0.14.1.txt

+2
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,5 @@ Bug Fixes
262262

263263
- Bug in non-monotonic ``Index.union`` may preserve ``name`` incorrectly (:issue:`7458`)
264264
- Bug in ``DatetimeIndex.intersection`` doesn't preserve timezone (:issue:`4690`)
265+
266+
- Bug in ``Float64Index`` assignment with a non scalar indexer (:issue:`7586`)

pandas/core/index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ def __contains__(self, other):
20742074

20752075
def get_loc(self, key):
20762076
try:
2077-
if np.isnan(key):
2077+
if np.all(np.isnan(key)):
20782078
try:
20792079
return self._nan_idxs.item()
20802080
except ValueError:

pandas/tests/test_indexing.py

+12
Original file line numberDiff line numberDiff line change
@@ -3684,6 +3684,18 @@ def test_duplicate_ix_returns_series(self):
36843684
e = df.loc[0.2, 'a']
36853685
tm.assert_series_equal(r, e)
36863686

3687+
def test_float_index_non_scalar_assignment(self):
3688+
df = DataFrame({'a': [1,2,3], 'b': [3,4,5]},index=[1.,2.,3.])
3689+
df.loc[df.index[:2]] = 1
3690+
expected = DataFrame({'a':[1,1,3],'b':[1,1,5]},index=df.index)
3691+
tm.assert_frame_equal(expected, df)
3692+
3693+
df = DataFrame({'a': [1,2,3], 'b': [3,4,5]},index=[1.,2.,3.])
3694+
df2 = df.copy()
3695+
df.loc[df.index] = df.loc[df.index]
3696+
tm.assert_frame_equal(df,df2)
3697+
3698+
36873699

36883700
if __name__ == '__main__':
36893701
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

0 commit comments

Comments
 (0)