Skip to content

BUG: Exception when setting a major- or minor-axis slice of a Panel with RHS a DataFrame #11021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2015
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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
10 changes: 7 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down