Skip to content

Commit

Permalink
Fixes #225
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Apr 7, 2021
1 parent 37aa95c commit 0d663ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/tech/v3/dataset/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
index-seq - either keyword :all or list of indexes. May contain duplicates.
"
[dataset colname-seq index-seq]
(when (dtype-proto/has-constant-time-min-max? index-seq)
(when (and index-seq (dtype-proto/has-constant-time-min-max? index-seq))
(let [lmin (long (dtype-proto/constant-time-min index-seq))
lmax (long (dtype-proto/constant-time-max index-seq))]
(errors/when-not-errorf
Expand All @@ -253,10 +253,12 @@
(let [index-seq (if (number? index-seq)
[index-seq]
index-seq)]
(when-not (or (nil? colname-seq)
(and (sequential? colname-seq)
(nil? (seq colname-seq))))
(ds-proto/select dataset colname-seq index-seq))))
(if-not (or (nil? colname-seq)
(and (sequential? colname-seq)
(nil? (seq colname-seq)))
(nil? index-seq))
(ds-proto/select dataset colname-seq index-seq)
(ds-impl/empty-dataset))))

(defn select-by-index
"Trim dataset according to this sequence of indexes. Returns a new dataset.
Expand Down
14 changes: 9 additions & 5 deletions src/tech/v3/dataset/impl/dataset.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
(set! *warn-on-reflection* true)


(declare new-dataset map-entries)
(declare new-dataset map-entries empty-dataset)

;;ported from clojure.lang.APersistentMap
(defn- map-equiv [this o]
Expand Down Expand Up @@ -162,10 +162,7 @@
(when-let [v (.valAt this k)]
(clojure.lang.MapEntry. k v)))
;;No idea if this is correct behavior....
(empty [this] (new-dataset
"_unnamed"
{:name "_unnamed"}
[]))
(empty [this] (empty-dataset))
;;ported from clojure java impl.
(cons [this e]
(cond (instance? java.util.Map$Entry e)
Expand Down Expand Up @@ -450,3 +447,10 @@
(defn dataset?
[ds]
(instance? Dataset ds))


(defn empty-dataset
[]
(new-dataset
"_unnamed"
nil))
6 changes: 6 additions & 0 deletions test/tech/v3/dataset_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,12 @@
(is (= 4 (ds/row-count data)))))


(deftest empty-dataset-on-select-nothing
(let [dataset (ds/->dataset "test/data/stocks.csv")]
(is (= 0 (ds/row-count (ds/select-columns dataset nil))))
(is (= 0 (ds/row-count (ds/select-rows dataset nil))))))


(comment

(def test-ds (ds/->dataset
Expand Down

0 comments on commit 0d663ca

Please sign in to comment.