diff --git a/doc/source/whatsnew/v0.17.0.txt b/doc/source/whatsnew/v0.17.0.txt index 1a976bf0d921e..4ea4f0a5ab307 100644 --- a/doc/source/whatsnew/v0.17.0.txt +++ b/doc/source/whatsnew/v0.17.0.txt @@ -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`) diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 1293b4034b84e..08ef82835830c 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -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) diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index 7c67ded16139c..bd27d11ef14c1 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -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 @@ -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