Skip to content

Commit

Permalink
Refactor ->clj, now it should be faster
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmarazzi committed Jul 8, 2019
1 parent e331ad0 commit 170a7e7
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/panthera/pandas/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,32 @@

(defn keys->pyargs
[m]
(let [nm (reduce-kv
(fn [m k v]
(assoc m k (vals->pylist v)))
{} m)]
(let [nm (reduce-kv
(fn [m k v]
(assoc m k (vals->pylist v)))
{} m)]
(cske/transform-keys memo-key-converter nm)))

(defn series?
[obj]
(identical? :series (pytype obj)))

(defn data-frame?
[obj]
(identical? :data-frame (pytype obj)))

(defn ->clj
[df-or-srs]
(let [v (py/get-attr df-or-srs "values")
tp ({:data-frame "columns"
:series "name"} (pytype df-or-srs))
ks (py/get-attr df-or-srs tp)]
(if (= tp "columns")
(map #(zipmap
(map memo-columns-converter (vec ks)) %) v)
(map #(hash-map
(memo-columns-converter (or ks :unnamed)) %) v))))
(if (series? df-or-srs)
(let [nm (or (memo-columns-converter
(py/get-attr df-or-srs "name"))
:unnamed)]
(into [] (map #(assoc {} nm %))
(vec df-or-srs)))
(let [ks (map memo-columns-converter
(py/get-attr df-or-srs "columns"))]
(into [] (map #(zipmap ks %))
(py/get-attr df-or-srs "values")))))

(defn simple-kw-call
[df kw & [attrs]]
Expand All @@ -70,12 +79,4 @@
(defn kw-call
[df kw pos & [attrs]]
(py/call-attr-kw df kw [pos]
(keys->pyargs attrs)))

(defn series?
[obj]
(identical? :series (pytype obj)))

(defn data-frame?
[obj]
(identical? :data-frame (pytype obj)))
(keys->pyargs attrs)))

0 comments on commit 170a7e7

Please sign in to comment.