Skip to content

Commit

Permalink
[select] working with a Clojure vector of bools
Browse files Browse the repository at this point in the history
 - tests pass
 - confusing things are now possible: `(ds/select ds :all [true :true :false nil :nil 17])`
 - Fixes :#387
  • Loading branch information
harold committed Jan 24, 2024
1 parent 6ebb6cb commit a017bf7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tech/v3/dataset/impl/column.clj
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
(cond
(nil? selection) (hamf/range 0)
;;Cannot possibly be negative
(= (dtype/elemwise-datatype selection) :boolean)
(and (sequential? selection) (boolean? (first selection)))
(un-pred/bool-reader->indexes (dtype/ensure-reader selection))
(set/bitset? selection)
(set/->integer-random-access selection)
Expand Down
10 changes: 10 additions & 0 deletions test/tech/v3/dataset_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,16 @@

(is (= 3 (count (get data (int 0)))))))

(deftest select-bool-issue-387
(let [ds (ds/->dataset {:a (range 10)})
vec-of-bools [true false true false true false true false true false]
expected [0 2 4 6 8]]
(is (= expected
(-> (ds/select ds :all (dtype/make-list :boolean vec-of-bools))
:a)))
(is (= expected
(-> (ds/select ds :all vec-of-bools)
:a)))))

(comment
(require '[criterium.core :as crit])
Expand Down

0 comments on commit a017bf7

Please sign in to comment.