Skip to content

Commit f1aee70

Browse files
committed
ER: GH3777, raise a NotImplementedError for Panel -> Panel setting with alignment
1 parent 0f72731 commit f1aee70

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pandas 0.13
132132
- Fixed Panel slicing issued in ``xs`` that was returning an incorrect dimmed object
133133
(:issue:`4016`)
134134
- Fixed Panel assignment with a transposed frame (:issue:`3830`)
135+
- Raise on set indexing with a Panel and a Panel as a value which needs alignment (:issue:`3777`)
135136

136137
pandas 0.12
137138
===========

pandas/core/indexing.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _convert_tuple(self, key):
100100
return tuple(keyidx)
101101

102102
def _setitem_with_indexer(self, indexer, value):
103-
from pandas.core.frame import DataFrame, Series
103+
from pandas import Panel, DataFrame, Series
104104

105105
# also has the side effect of consolidating in-place
106106

@@ -181,6 +181,9 @@ def setter(item, v):
181181
if isinstance(value, DataFrame):
182182
value = self._align_frame(indexer, value)
183183

184+
if isinstance(value, Panel):
185+
value = self._align_panel(indexer, value)
186+
184187
# 2096
185188
values = self.obj.values
186189
if np.prod(values.shape):
@@ -269,6 +272,11 @@ def _align_frame(self, indexer, df):
269272

270273
raise ValueError('Incompatible indexer with DataFrame')
271274

275+
def _align_panel(self, indexer, df):
276+
is_frame = self.obj.ndim == 2
277+
is_panel = self.obj.ndim >= 3
278+
raise NotImplementedError("cannot set using an indexer with a Panel yet!")
279+
272280
def _getitem_tuple(self, tup):
273281
try:
274282
return self._getitem_lowerdim(tup)

pandas/tests/test_indexing.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -877,12 +877,27 @@ def test_panel_getitem(self):
877877
# GH4016, date selection returns a frame when a partial string selection
878878
ind = date_range(start="2000", freq="D", periods=1000)
879879
df = DataFrame(np.random.randn(len(ind), 5), index=ind, columns=list('ABCDE'))
880-
panel = Panel({'frame_'+c:df for c in list('ABC')})
880+
panel = Panel(dict([ ('frame_'+c,df) for c in list('ABC') ]))
881881

882882
test2 = panel.ix[:, "2002":"2002-12-31"]
883883
test1 = panel.ix[:, "2002"]
884884
tm.assert_panel_equal(test1,test2)
885885

886+
def test_panel_assignment(self):
887+
888+
# GH3777
889+
wp = Panel(randn(2, 5, 4), items=['Item1', 'Item2'], major_axis=date_range('1/1/2000', periods=5), minor_axis=['A', 'B', 'C', 'D'])
890+
wp2 = Panel(randn(2, 5, 4), items=['Item1', 'Item2'], major_axis=date_range('1/1/2000', periods=5), minor_axis=['A', 'B', 'C', 'D'])
891+
expected = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]
892+
893+
def f():
894+
wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = wp2.loc[['Item1', 'Item2'], :, ['A', 'B']]
895+
self.assertRaises(NotImplementedError, f)
896+
897+
#wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = wp2.loc[['Item1', 'Item2'], :, ['A', 'B']]
898+
#result = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]
899+
#tm.assert_panel_equal(result,expected)
900+
886901
def test_multi_assign(self):
887902

888903
# GH 3626, an assignement of a sub-df to a df

0 commit comments

Comments
 (0)