Skip to content

Commit 597aa42

Browse files
terrytangyuanjreback
authored andcommitted
ERR/API: Raise NotImplementedError when Panel operator function is not implemented, #7692
1 parent 581d5be commit 597aa42

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v0.17.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ Bug Fixes
11081108
- Bug causes memory leak in time-series line and area plot (:issue:`9003`)
11091109

11101110
- Bug when setting a ``Panel`` sliced along the major or minor axes when the right-hand side is a ``DataFrame`` (:issue:`11014`)
1111-
1111+
- Bug that returns ``None`` and does not raise ``NotImplementedError`` when operator functions (e.g. ``.add``) of ``Panel`` are not implemented (:issue:`7692`)
11121112

11131113
- Bug in line and kde plot cannot accept multiple colors when ``subplots=True`` (:issue:`9894`)
11141114
- Bug in ``DataFrame.plot`` raises ``ValueError`` when color name is specified by multiple characters (:issue:`10387`)

pandas/core/panel.py

+4
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,10 @@ def _combine(self, other, func, axis=0):
679679
return self._combine_frame(other, func, axis=axis)
680680
elif np.isscalar(other):
681681
return self._combine_const(other, func)
682+
else:
683+
raise NotImplementedError(str(type(other)) +
684+
' is not supported in combine operation with ' +
685+
str(type(self)))
682686

683687
def _combine_const(self, other, func):
684688
new_values = func(self.values, other)

pandas/tests/test_panel.py

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import nose
88

99
import numpy as np
10+
import pandas as pd
1011

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

358+
# issue 7692
359+
def test_raise_when_not_implemented(self):
360+
p = Panel(np.arange(3*4*5).reshape(3,4,5), items=['ItemA','ItemB','ItemC'],
361+
major_axis=pd.date_range('20130101',periods=4),minor_axis=list('ABCDE'))
362+
d = p.sum(axis=1).ix[0]
363+
ops = ['add', 'sub', 'mul', 'truediv', 'floordiv', 'div', 'mod', 'pow']
364+
for op in ops:
365+
with self.assertRaises(NotImplementedError):
366+
getattr(p,op)(d, axis=0)
367+
357368
def test_select(self):
358369
p = self.panel
359370

0 commit comments

Comments
 (0)