Skip to content

Commit

Permalink
Merge pull request #167 from schneiderlin/zihao/compare
Browse files Browse the repository at this point in the history
Fix sorting regression for non-numerical columns
  • Loading branch information
genmeblog authored Sep 3, 2024
2 parents 8f40c7b + d6e4dcc commit 632e8bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{:extra-paths ["data"]
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
techascent/tech.ml.dataset {:mvn/version "7.029"}}
techascent/tech.ml.dataset {:mvn/version "7.030"}}
:aliases {:dev {:extra-deps {org.scicloj/clay {:mvn/version "2-beta11"}
org.scicloj/note-to-test {:mvn/version "1-alpha7"}}}
:test {:extra-deps {org.scicloj/clay {:mvn/version "2-beta11"}
Expand Down
8 changes: 4 additions & 4 deletions src/tablecloth/column/api/column.clj
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@
(fn? order-or-comparator)))
(throw (IllegalArgumentException.
"`order-or-comparator` must be `:asc`, `:desc`, or a function.")))
(let [order-fn-lookup {:asc fun/<, :desc fun/>}
comparator-fn (if (fn? order-or-comparator)
order-or-comparator
(order-fn-lookup order-or-comparator))
(let [comparator-fn (cond
(fn? order-or-comparator) order-or-comparator
(= :asc order-or-comparator) compare
(= :desc order-or-comparator) #(compare %2 %1))
sorted-indices (argsort comparator-fn col)]
(col/select col sorted-indices))))

Expand Down

0 comments on commit 632e8bc

Please sign in to comment.