From edc031e1de1eb27884145709122600a2d62dd43a Mon Sep 17 00:00:00 2001 From: Epidiah Ravachol Date: Tue, 1 Oct 2024 17:08:57 -0400 Subject: [PATCH 1/2] Treat bindings in let-dataset as columns --- src/tablecloth/api/api_template.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tablecloth/api/api_template.clj b/src/tablecloth/api/api_template.clj index 7b80ccc..6d1e86e 100644 --- a/src/tablecloth/api/api_template.clj +++ b/src/tablecloth/api/api_template.clj @@ -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 @@ -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))))) From 1101068fcb1b4702d02306fd83eabba298411db4 Mon Sep 17 00:00:00 2001 From: Epidiah Ravachol Date: Thu, 3 Oct 2024 10:39:04 -0400 Subject: [PATCH 2/2] Add test for let-dataset macro --- test/tablecloth/api/dataset_test.clj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/tablecloth/api/dataset_test.clj b/test/tablecloth/api/dataset_test.clj index 7694853..3855c0d 100644 --- a/test/tablecloth/api/dataset_test.clj +++ b/test/tablecloth/api/dataset_test.clj @@ -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]]) @@ -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]})))