Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat bindings in let-dataset as columns #171

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]})))
Loading