pydata/pandas — pull request #4560 by jtratner (2013-08-14 01:17:18+00:00)
Title: CLN/ENH: Provide full suite of arithmetic (and flex) methods to all NDFrame objects.

Resolves #3765, #4331, #4334.

This goes on top of @jreback's Series refactoring (#3482). If you want to review, I suggest looking [at the PR on top of jreback/series2](https://github.com/jreback/pandas/pull/6), so you only see the diffs specific to this PR.

This does a few things:
1. Normalizes the arithmetic signature so that all objects have the full-range of special methods, inplace methods and `__r*__` methods. Similarly, most objects get the full-range of flex methods (varies based on the object.
2. Refactors all arithmetic methods to `core/ops` and adds methods to add both special (e.g., `__add__`) and flex (e.g. `add()`) to PandasObjects.
3. Slight refactoring of the arithmetic methods themselves to abstract the common `na_op` idiom into a single function.
4. Uses `numexpr` throughout for most operations (except for `SparsePanel` which doesn't respond to shape so can't be used with it).
5. Makes it easier to create new `PandasObjects` that support all arithmetic methods - just need to define 2-5 functions.
6. Establishes a standard type signature for arithmetic methods [documented in core/ops], specifically:
* arithmetic method: `f(op, name, str_rep, default_axis=None, fill_zeros=None, **eval_kwargs)`
* comp/bool method: `f(op, name, str_rep)`

This is a straight continuation of #4051, but since it's different enough (especially with moving the operations to core/ops and no longer using them as classmethods), I'm doing it in a separate PR.

I'm open to changing the naming of the arithmetic functions in core/ops. I named them as they are to make it easier to move them into `core/ops`

Sidenote: I don't know whether numexpr plays well with sparse objects (or if that's even an issue). It's trivial to disable numexpr on Sparse\* objects, just need to know what you want to do.