Skip to content

Commit

Permalink
Merge pull request #171 from Epidiah/let-dataset-pr
Browse files Browse the repository at this point in the history
Treat bindings in let-dataset as columns
  • Loading branch information
genmeblog authored Oct 4, 2024
2 parents 4f81d3a + 1101068 commit 662bd7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/tablecloth/api/api_template.clj
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
pivot->longer
pivot->wider)

(exporter/export-symbols tablecloth.api.join-concat-ds
(exporter/export-symbols tablecloth.api.join-concat-ds
left-join
right-join
inner-join
Expand Down Expand Up @@ -166,7 +166,7 @@
([bindings] `(let-dataset ~bindings nil))
([bindings options]
(let [cols (take-nth 2 bindings)
col-defs (mapv vector (map keyword cols) cols)]
col-defs (into (array-map) (map vector (map keyword cols) cols))]
`(let [~@bindings]
(dataset ~col-defs ~options)))))

Expand Down
7 changes: 7 additions & 0 deletions test/tablecloth/api/dataset_test.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns tablecloth.api.dataset-test
(:require [tablecloth.api :as api]
[tablecloth.column.api :as tcc]
[tablecloth.common-test :refer [DS]]
[clojure.java.io :as io]
[midje.sweet :refer [tabular fact => throws]])
Expand Down Expand Up @@ -128,3 +129,9 @@
?f ?v
api/rows '((1.0 5.0) (2.0 6.0) (3.0 7.0))
api/columns '((1.0 2.0 3.0) (5.0 6.0 7.0))))

(fact "let-dataset"
(fact (api/let-dataset [x (range 4) y 10 z (tcc/+ x y)])
=> (api/dataset {:x [0 1 2 3]
:y [10 10 10 10]
:z [10 11 12 13]})))

0 comments on commit 662bd7d

Please sign in to comment.