Skip to content

Commit

Permalink
Make math to act more like core functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmarazzi committed Jul 8, 2019
1 parent e955cc1 commit 8065924
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions src/panthera/pandas/math.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 :+))
Expand Down

0 comments on commit 8065924

Please sign in to comment.