Skip to content

ERR/API: Raise NotImplementedError when method is not implemented (issue: 7692) #11095

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

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 1 deletion doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ 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 that returns ``None`` and does not raise `NotImplementedError` when operator functions of ``Panel`` are not implemented (:issue:`7692`)

- 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
4 changes: 4 additions & 0 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,10 @@ def _combine(self, other, func, axis=0):
return self._combine_frame(other, func, axis=axis)
elif np.isscalar(other):
return self._combine_const(other, func)
else:
raise NotImplementedError(str(type(other)) +
' is not supported in combine operation with ' +
str(type(self)))

def _combine_const(self, other, func):
new_values = func(self.values, other)
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import nose

import numpy as np
import pandas as pd

from pandas import Series, DataFrame, Index, isnull, notnull, pivot, MultiIndex
from pandas.core.datetools import bday
Expand Down Expand Up @@ -354,6 +355,16 @@ def test_combinePanel(self):
def test_neg(self):
self.assert_panel_equal(-self.panel, self.panel * -1)

# issue 7692
def test_raise_when_not_implemented(self):
p = Panel(np.arange(3*4*5).reshape(3,4,5), items=['ItemA','ItemB','ItemC'],
major_axis=pd.date_range('20130101',periods=4),minor_axis=list('ABCDE'))
d = p.sum(axis=1).ix[0]
ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'div', 'mod', 'pow']
for op in ops:
with self.assertRaises(NotImplementedError):
getattr(p,op)(d, axis=0)

def test_select(self):
p = self.panel

Expand Down