Taken from #4960
Currently Panel arith methods only work with scalars.
https://github.com/jreback/pandas/commit/adf9d48bf2cca5f25c00f780825c36feafa05bf1
removes the explicit check, but need to make sure it works with tests.
Comment From: dalejung
@jreback Is there a general way to think about arith methods for NDFrames?
From what I can tell.
1. If other
is scalar, result should be the same as op(val, other)
for every element in .values.
2. Any array-like other
must have self.ndim >= other.ndim
3. If other
is array-like but not an NDFrame, it must match the shape of axes it's applying to. Lower dim other
will be broadcasted along the unused axis.
4. If other
is NDFrame
, outer join the objects and then op
the aligned objects. Lower dim other
broadcast like regular array once alignment occurs.
I think those rules should be true for all NDFrames, regardless of dimensions. However, this breaks down in my head when it comes to #4 and Panel/4D.
DataFrame.mul(Series, axis='columns')
can add a column in the resultant DataFrame
.
However, Panel.mul(DataFrame, axis='items')
could never expand items
.
Is the issue that technically axis should be Panel.mul(DataFrame, axis=('major', 'minor')
and we items
as convenience? If we were multiplying a Panel4D by a DataFrame, how would we specify the axis?
Probably overthinking it but wanted a programatic way to test arith methods on all NDFrame subclasses.
Comment From: jreback
see the _combine
method, which tests each of these cases, e.g. scalar, series, frame, panel, > panel
and on anything > 2 dims we don't (or shouldn't) support an ndarray because its unclear how to align it (unless it exactly matches dims, so its clear) - I don't think is really tested either (though maybe combine falls thru and so it raises)
IOW, leary of doing any sort of automatic broadcasting with > 2 dims (except via specific .mul
methods which provide a broadcasting axis)
as far as those go, there is a note in the docs about how wes decided to handle them, somewhere in basicas. (so i think you are right in that regards).
Comment From: jtratner
Hey all, please wait on this until after I refactor arithmetic. I'd rather you work on this after I've set up the general structure, rather than me having to wrap my head around something new and try not to break it while refactoring.
Comment From: jreback
@jtratner no worries!
@dalejung you can certianly start working on tests if you would like in any event as they will be relevant
Comment From: jreback
closing as Panels are deprecated