diff --git a/doc/source/whatsnew/v0.17.0.txt b/doc/source/whatsnew/v0.17.0.txt index f88e5c0a11f9f..4e8cfdfa16a12 100644 --- a/doc/source/whatsnew/v0.17.0.txt +++ b/doc/source/whatsnew/v0.17.0.txt @@ -964,6 +964,8 @@ Bug Fixes - Bug causes memory leak in time-series line and area plot (:issue:`9003`) +- Bug when setting a ``Panel`` sliced along the major or minor axes when the right-hand side is a ``DataFrame`` (:issue:`11014`) + - Bug in line and kde plot cannot accept multiple colors when ``subplots=True`` (:issue:`9894`) - Bug in ``DataFrame.plot`` raises ``ValueError`` when color name is specified by multiple characters (:issue:`10387`) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 7cf1942046e75..71bba3a9edea2 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -442,11 +442,15 @@ def can_do_equal_len(): # we have an equal len Frame if isinstance(value, ABCDataFrame) and value.ndim > 1: + sub_indexer = list(indexer) for item in labels: - # align to - v = np.nan if item not in value else \ - self._align_series(indexer[0], value[item]) + if item in value: + sub_indexer[info_axis] = item + v = self._align_series(tuple(sub_indexer), value[item]) + else: + v = np.nan + setter(item, v) # we have an equal len ndarray/convertible to our labels diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index d45e6e50cafb3..7c67ded16139c 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -506,6 +506,20 @@ def test_setitem_ndarray(self): assert_almost_equal(P[key].values, data) + def test_set_minor_major(self): + # GH 11014 + df1 = DataFrame(['a', 'a', 'a', np.nan, 'a', np.nan]) + df2 = DataFrame([1.0, np.nan, 1.0, np.nan, 1.0, 1.0]) + panel = Panel({'Item1' : df1, 'Item2': df2}) + + newminor = notnull(panel.iloc[:, :, 0]) + panel.loc[:, :, 'NewMinor'] = newminor + assert_frame_equal(panel.loc[:, :, 'NewMinor'], newminor.astype(object)) + + newmajor = notnull(panel.iloc[:, 0, :]) + panel.loc[:, 'NewMajor', :] = newmajor + assert_frame_equal(panel.loc[:, 'NewMajor', :], newmajor.astype(object)) + def test_major_xs(self): ref = self.panel['ItemA']