From 9a7a7c80a284e45237299b5c6474e4485d921ef6 Mon Sep 17 00:00:00 2001 From: terrytangyuan Date: Mon, 14 Sep 2015 11:15:02 -0400 Subject: [PATCH] ERR/API: Raise NotImplementedError when Panel operator function is not implemented (issue: 7692) (+1 squashed commit) Squashed commits: [9c56cd0] ERR/API: Raise NotImplementedError when Panel operator function is not implemented (issue: 7692) (+1 squashed commit) Squashed commits: [6c036e5] ERR/API: Raise NotImplementedError when Panel operator function is not implemented (issue: 7692) (+1 squashed commit) Squashed commits: [1e8ff32] ERR/API: Raise NotImplementedError when Panel operator function is not implemented (issue: 7692) (+1 squashed commit) Squashed commits: [7b487c7] ERR/API: Raise NotImplementedError when Panel operator function is not implemented (issue: 7692) (+1 squashed commit) Squashed commits: [9e7aa80] ERR/API: Raise NotImplementedError when method is not implemented (issue: 7692) (+1 squashed commit) Squashed commits: [17fadd1] ERR/API: Raise NotImplementedError when method is not implemented (issue: 7692) (+1 squashed commit) Squashed commits: [4b149df] ERR/API: Raise NotImplementedError when method is not implemented in Panel.py (issue: 7692) (+1 squashed commit) Squashed commits: [8832b74] ERR/API: Raise NotImplementedError when method is not implemented (issue: 7692) (+1 squashed commit) Squashed commits: [fc01bf8] ERR/API: Raise NotImplementedError when method is not implemented (issue: 7692) (+1 squashed commit) Squashed commits: [a04c4a2] raise error when not implemented --- doc/source/whatsnew/v0.17.0.txt | 2 +- pandas/core/panel.py | 4 ++++ pandas/tests/test_panel.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) 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