Skip to content

Commit

Permalink
Fixes #260
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Aug 18, 2021
1 parent 71ecdfa commit fde778c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.10.3" :scope "provided"]
[cnuernber/dtype-next "8.024-SNAPSHOT"]
[cnuernber/dtype-next "8.024"]
[techascent/tech.io "4.09"
:exclusions [org.apache.commons/commons-compress]]
[com.univocity/univocity-parsers "2.9.0"]
Expand Down
8 changes: 4 additions & 4 deletions src/tech/v3/dataset/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -513,21 +513,21 @@

(defn sort-by
"Sort a dataset by a key-fn and compare-fn."
([dataset key-fn compare-fn]
([dataset key-fn compare-fn & [options]]
(when dataset
(->> (ds-readers/mapseq-reader dataset)
(dtype/emap key-fn :object)
(argops/argsort compare-fn)
(argops/argsort compare-fn options)
(select dataset :all))))
([dataset key-fn]
(sort-by dataset key-fn nil)))


(defn sort-by-column
"Sort a dataset by a given column using the given compare fn."
([dataset colname compare-fn]
([dataset colname compare-fn & [options]]
(when dataset
(->> (argops/argsort compare-fn (packing/unpack (dataset colname)))
(->> (argops/argsort compare-fn options (packing/unpack (dataset colname)))
(select dataset :all))))
([dataset colname]
(sort-by-column dataset colname nil)))
Expand Down
20 changes: 18 additions & 2 deletions test/tech/v3/dataset_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,24 @@
(vec (dst-ds :b))))))


#_(deftest concat-packed-date-with-date-results-in-local-date-or-packed-local-date
(throw (Exception. "This failed in practice")))
(deftest sort-works-with-nan
(let [ds (ds/->dataset {:a [1 nil 2 nil nil 4]} )
ds-first (ds/sort-by-column ds :a nil {:nan-strategy :first})
ds-last (ds/sort-by-column ds :a nil {:nan-strategy :last})]
(is (= [nil nil nil 1 2 4] (vec (ds-first :a))))
(is (= [1 2 4 nil nil nil] (vec (ds-last :a))))
(is (thrown? Exception (ds/sort-by-column ds :a nil {:nan-strategy :exception})))))


(deftest concat-packed-date-with-date-results-in-local-date-or-packed-local-date
(let [ds (ds/->dataset (repeat 10 {:a (dtype-dt/local-date)})
{:parser-fn {:a :local-date}})
ds-packed (ds/->dataset {:a (repeat 10 (dtype-dt/local-date))}
{:parser-fn {:a :packed-local-date}})
res-inp (ds/concat-inplace ds ds-packed)
res-cp (ds/concat-copying ds ds-packed)]
(is (#{:local-date :packed-local-date} (dtype/elemwise-datatype (res-inp :a))))
(is (#{:local-date :packed-local-date} (dtype/elemwise-datatype (res-cp :a))))))


(comment
Expand Down

0 comments on commit fde778c

Please sign in to comment.