ERR/API: raise NotImplemented for Panel broadcastables with non-scalar #7692

Closed
jreback opened this Issue Jul 8, 2014 · 3 comments

Comments

Projects
None yet
2 participants
Contributor

jreback commented Jul 8, 2014

This works fine
http://stackoverflow.com/questions/24631991/division-of-a-panel-by-a-series/24632381#24632381

[8]: p = Panel(np.arange(3*4*5).reshape(3,4,5),items=['ItemA','ItemB','ItemC'],major_axis=date_range('20130101',periods=4),minor_axis=list('ABCDE'))

In [9]: p
Out[9]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 4 (major_axis) x 5 (minor_axis)
Items axis: ItemA to ItemC
Major_axis axis: 2013-01-01 00:00:00 to 2013-01-04 00:00:00
Minor_axis axis: A to E

In [10]: d = p.sum(axis=1).ix[0]

In [11]: d
Out[11]: 
ItemA     30
ItemB    110
ItemC    190
Name: A, dtype: int64

In [12]: p.iloc[0]
Out[12]: 
             A   B   C   D   E
2013-01-01   0   1   2   3   4
2013-01-02   5   6   7   8   9
2013-01-03  10  11  12  13  14
2013-01-04  15  16  17  18  19

In [13]: p.apply(lambda x: x/d,axis=0).iloc[0]
Out[13]: 
                   A         B         C         D         E
2013-01-01  0.000000  0.033333  0.066667  0.100000  0.133333
2013-01-02  0.166667  0.200000  0.233333  0.266667  0.300000
2013-01-03  0.333333  0.366667  0.400000  0.433333  0.466667
2013-01-04  0.500000  0.533333  0.566667  0.600000  0.633333

p.div(d,axis=0) should raise NotImplementedError instead of returning None.

https://github.com/pydata/pandas/blob/master/pandas/core/panel.py#L655
needs an else that raises.

Of course this can/should be implemented.

jreback added this to the 0.15.0 milestone Jul 8, 2014

@jreback jreback modified the milestone: 0.15.0, 0.15.1 Sep 8, 2014

@jreback jreback modified the milestone: 0.16.0, Next Major Release Mar 6, 2015

Contributor

terrytangyuan commented Sep 14, 2015

@jreback Do you mean something like this? The line you highlighted is outdated so I am not sure what you meant.

diff --git a/pandas/core/panel.py b/pandas/core/panel.py
index 1293b40..5d9ff28 100644
--- a/pandas/core/panel.py
+++ b/pandas/core/panel.py
@@ -631,6 +631,9 @@ class Panel(NDFrame):
     def align(self, other, **kwargs):
         raise NotImplementedError

+    def div(self, d, axis=0):
+        raise NotImplementedError
+
     def dropna(self, axis=0, how='any', inplace=False):
         """
         Drop 2D from panel, holding passed axis constant
Contributor

jreback commented Sep 14, 2015

no this should raise in core/panel.py/_combine. a Series just gets passed thru silently.
Though the real soln to make .align work.

@jreback jreback modified the milestone: 0.17.0, Next Major Release Sep 17, 2015

Contributor

jreback commented Sep 21, 2015

closed by #11095

jreback closed this Sep 21, 2015

@yarikoptic yarikoptic added a commit to neurodebian/pandas that referenced this issue Oct 11, 2015

@yarikoptic yarikoptic Merge commit 'v0.17.0rc1-92-gc6bcc99' into debian
* commit 'v0.17.0rc1-92-gc6bcc99': (29 commits)
  CI: tests latest versions of openpyxl
  COMPAT: openpyxl >= 2.2 support, #10125
  Tests demonstrating how to use sqlalchemy.text() objects in read_sql()
  TST: Capture warnings in _check_plot_works
  COMPAT/BUG: color handling in scatter
  COMPAT: Support for matplotlib 1.5
  ERR/API: Raise NotImplementedError when Panel operator function is not implemented, #7692
  DOC: minor doc formatting fixes
  PERF: nested dict DataFrame construction
  DEPR: deprecate SparsePanel
  BLD: dateutil->python-dateutil in conda recipe
  BUG/API: GH11086 where freq is not inferred if both freq is None
  ENH: add merge indicator to DataFrame.merge
  PERF: improves performance in groupby.size
  BUG: DatetimeTZBlock.fillna raises TypeError
  PERF: infer_datetime_format without padding #11142
  PERF: improves performance in SeriesGroupBy.transform
  TST: Verify fix for buffer overflow in read_csv with engine='c' (GH #9735)
  DEPR: Series.is_timeseries
  BUG: nested construction with timedelta #11129
  ...
cdbb0ff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment