BUG/API: Fix operating with timedelta64/pd.offsets on rhs of a datelike series/index by jreback · Pull Request #4534 · pandas-dev/pandas (original) (raw)

@jreback so the problem is that, with how the arithmetic functions (and r* funcs in general) are set up:

get the same call signature for self, other in wrapper, and you only know what's going on because of the name variable that's passed along. So, would it work to just do:

earlier

if r_op: external_op = op op = lambda x, y: external_op(y, x) if r_op: rvalues, lvalues = self, other else: lvalues, rvalues = self, other

and then flip the ops when they actually get passed to the operation (since all r ops can't currently be passed well through core.expressions.evaluate). This ends up with the following chain of operations [specific to series, because it's the only one that actually cares about left and right values]:

#r_op passed into arith_method
r_op = lambda x, y: operator.add(y, x)
internal_op = lambda a, b: r_op(b, a)
# inside method
rvalues, lvalues = self, other
# finally at end, gets called
internal_op(lvalues, rvalues) --> internal_op(other, self) --> r_op(self, other) --> operator.add(other, self)

That should make all the checks work for it, right?