From 8065924a407c7ae31ab5e29b612897cf46533230 Mon Sep 17 00:00:00 2001 From: alanmarazzi Date: Mon, 8 Jul 2019 20:56:31 +0200 Subject: [PATCH] Make math to act more like core functions --- src/panthera/pandas/math.clj | 55 +++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/panthera/pandas/math.clj b/src/panthera/pandas/math.clj index 1d33da1..f143888 100644 --- a/src/panthera/pandas/math.clj +++ b/src/panthera/pandas/math.clj @@ -7,23 +7,44 @@ (defn- base-math [k] - (fn [df-or-srs other & [attrs]] - (u/kw-call df-or-srs - ({:+ "add" - :- "sub" - :* "mul" - :div "div" - :mode "mod" - :** "pow" - :< "lt" - :> "gt" - :<= "le" - :>= "ge" - :!= "ne" - := "eq" - :dot "dot"} k) - other - attrs))) + (fn [& args] + (reduce #(py/call-attr %1 + ({:+ "__add__" + :- "__sub__" + :* "__mul__" + :div "__div__" + :fld "__floordiv__" + :mod "__mod__" + :** "__pow__" + :< "__lt__" + :> "__gt__" + :<= "__le__" + :>= "__ge__" + :!= "__ne__" + := "__eq__" + :dot "__matmul__"} k) + %2) args))) + +(defn ops + [df-or-srs other op & [attrs]] + (u/kw-call + df-or-srs + ({:+ "__add__" + :- "__sub__" + :* "__mul__" + :div "__div__" + :fld "__floordiv__" + :mod "__mod__" + :** "__pow__" + :< "__lt__" + :> "__gt__" + :<= "__le__" + :>= "__ge__" + :!= "__ne__" + := "__eq__" + :dot "__matmul__"} op) + other + attrs)) (def add (base-math :+))