Skip to content
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.15.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ Bug Fixes

- Bug in ``cut``/``qcut`` when using ``Series`` and ``retbins=True`` (:issue:`8589`)
- Bug in numeric index operations of add/sub with Float/Index Index with numpy arrays (:issue:`8608`)
- Bug in ix/loc block splitting on setitem (manifests with integer-like dtypes, e.g. datetime64) (:issue:`8607`)
- Fix ``shape`` attribute for ``MultiIndex`` (:issue:`8609`)
8 changes: 8 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ def can_do_equal_len():
if isinstance(indexer, tuple):
indexer = _maybe_convert_ix(*indexer)

# if we are setting on the info axis ONLY
# set using those methods to avoid block-splitting
# logic here
if len(indexer) > info_axis and com.is_integer(indexer[info_axis]) and all(
_is_null_slice(idx) for i, idx in enumerate(indexer) if i != info_axis):
self.obj[item_labels[indexer[info_axis]]] = value
return

if isinstance(value, ABCSeries):
value = self._align_series(indexer, value)

Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,10 @@ def test_fancy_setitem_int_labels(self):
tmp = df.copy()
exp = df.copy()
tmp.ix[:, 2] = 5
exp.values[:, 2] = 5

# tmp correctly sets the dtype
# so match the exp way
exp[2] = 5
assert_frame_equal(tmp, exp)

def test_fancy_getitem_int_labels(self):
Expand Down
28 changes: 27 additions & 1 deletion pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ def test_iloc_setitem(self):
expected = Series([0,1,0],index=[4,5,6])
assert_series_equal(s, expected)

def test_loc_setitem(self):
def test_ix_loc_setitem(self):

# GH 5771
# loc with slice and series
s = Series(0,index=[4,5,6])
Expand All @@ -627,6 +628,31 @@ def test_loc_setitem(self):
expected = DataFrame({'a' : [0.5,-0.5,-1.5], 'b' : [0,1,2] })
assert_frame_equal(df,expected)

# GH 8607
# ix setitem consistency
df = DataFrame(
{'timestamp':[1413840976, 1413842580, 1413760580],
'delta':[1174, 904, 161],
'elapsed':[7673, 9277, 1470]
})
expected = DataFrame(
{'timestamp':pd.to_datetime([1413840976, 1413842580, 1413760580], unit='s'),
'delta':[1174, 904, 161],
'elapsed':[7673, 9277, 1470]
})

df2 = df.copy()
df2['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')
assert_frame_equal(df2,expected)

df2 = df.copy()
df2.loc[:,'timestamp'] = pd.to_datetime(df['timestamp'], unit='s')
assert_frame_equal(df2,expected)

df2 = df.copy()
df2.ix[:,2] = pd.to_datetime(df['timestamp'], unit='s')
assert_frame_equal(df2,expected)

def test_loc_setitem_multiindex(self):

# GH7190
Expand Down