larry-discuss team mailing list archive
-
larry-discuss team
-
Mailing list archive
-
Message #00158
General purpose binary operator
Here's a proposal for a general purpose binary operator for two data
objects. The language of the proposal (a doc string) is written in
terms of larry, but the ideas should be general enough for any
indexed/labeled data object. I plan to use something like this for
adding binary methods to larry such as larry.add(), larry.subtract(),
larry.divide(), etc. These new binary methods will give finer control
than the overloaded +, -, * etc.
I'm sending it out in hopes of getting some comments: design, variable
names, requests to stop spamming the list, anything.
def binaryop(func, lar1, lar2, join='inner', single=np.nan, double=np.nan)
"""
Binary operation on two larrys.
Parameters
----------
func : function
A function that takes two Numpy arrays as input and returns a Numpy
array as output. For example: np.add().
lar1 : larry
The larry on the left-hand side of the binary operation. Must have
the same number of dimensions as `lar2`.
lar2 : larry
The larry on the right-hand side of the binary operation. Must have
the same number of dimensions as `lar1`.
join : {'inner', 'outer', 'left', 'right', list}, optional
The method used to join the labels of the two larrys. The default join
method along each axis is 'inner', i.e., the intersection of the
labels. If `join` is a list then the length of the list must be the
number of dimensions of the two larrys. The first element in the list
is the join method for axis=0, the second element is the join method
for axis=1, and so on.
single : np.nan, optional
All elements that are missing in one larry but not missing in the
other are replace by `single`, which is NaN by default.
double : np.nan, optional
All elements that are missing in both larrys are replace by `double`,
which is NaN by default.
Returns
-------
lar3 : larry
The result of the binary operation.
"""
Follow ups