← Back to team overview

larry-discuss team mailing list archive

Re: [pystatsmodels] General purpose binary operator

 

On Tue, May 25, 2010 at 6:32 PM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
> 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.

Quick comment.  Single and double don't seem too informative to me as
names, and the double functionality seems redundant to me unless I
misunderstand.  Can you provide an example?

Also, I don't think I'd ever want my data to be dropped even if it's
missing in the other array.  I would propose the default of adding
nothing and taking the value from the other array.

Skipper



References