From da07f7186ae85ead2cfc8a119da05e1250d725d8 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Fri, 22 Apr 2022 14:22:37 -0700 Subject: [PATCH 01/20] Add namespace stub --- src/tablecloth/api/column.clj | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/tablecloth/api/column.clj diff --git a/src/tablecloth/api/column.clj b/src/tablecloth/api/column.clj new file mode 100644 index 0000000..82731ab --- /dev/null +++ b/src/tablecloth/api/column.clj @@ -0,0 +1,7 @@ +(ns tablecloth.api.column + (:refer-clojure :exclude [group-by]) + (:require [tech.v3.dataset :as ds] + [tech.v3.dataset.column :as col] + [tech.v3.datatype :as dtype])) + + From 9eae7fc7d0a75a350d46cde3b26c03f630178707 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Fri, 22 Apr 2022 14:33:44 -0700 Subject: [PATCH 02/20] Add super naive colunn fn --- src/tablecloth/api/column.clj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tablecloth/api/column.clj b/src/tablecloth/api/column.clj index 82731ab..9bbd1d4 100644 --- a/src/tablecloth/api/column.clj +++ b/src/tablecloth/api/column.clj @@ -5,3 +5,11 @@ [tech.v3.datatype :as dtype])) +(defn column + ([] (col/new-column nil [])) + ([data] + (column data {:name nil})) + ([data {:keys [name]}] + (col/new-column data))) + + From cfaffc61bb5c26e8ee02ac5f850bce2115bc851b Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sat, 30 Apr 2022 00:28:04 -0700 Subject: [PATCH 03/20] Add some simple column fns --- deps.edn | 2 +- docs/column_exploration.clj | 49 +++++++++++++++++++++++++++++++++++ src/tablecloth/api/column.clj | 12 +++++++-- 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 docs/column_exploration.clj diff --git a/deps.edn b/deps.edn index 2a8f2d3..5cecffc 100644 --- a/deps.edn +++ b/deps.edn @@ -4,4 +4,4 @@ ;; generateme/fastmath {:mvn/version "2.1.0"} } - :aliases {:dev {:extra-deps {org.scicloj/clay {:mvn/version "1-alpha9"}}}}} + :aliases {:dev {:extra-deps {org.scicloj/clay {:mvn/version "1-alpha11"}}}}} diff --git a/docs/column_exploration.clj b/docs/column_exploration.clj new file mode 100644 index 0000000..5a354a6 --- /dev/null +++ b/docs/column_exploration.clj @@ -0,0 +1,49 @@ +;; # Tablecloth Column Exploration + +^{:kind/hidden true} +(ns intro + (:require [tablecloth.api :as tc] + [scicloj.clay.v1.api :as clay] + [scicloj.clay.v1.tools :as tools] + [scicloj.clay.v1.tool.scittle :as scittle] + [scicloj.kindly.v2.kind :as kind] + [scicloj.clay.v1.view.dataset] + [nextjournal.clerk :as clerk])) + +^{:kind/hidden true} +(clay/start! {:tools [tools/scittle + tools/clerk]}) + +^{:kind/hidden true} +(comment + (clerk/show!) + + (do (scittle/show-doc! "docs/column_exploration.clj" {:hide-doc? true}) + (scittle/write-html! "docs/column_exploration.html")) + ,) + +;; ## What is this exploration? +;; +;; We want to add a `column` entity to tablecloth that parallels `dataset`. It will make +;; the column a first-class entity within tablecloth. + +;; ## Usage + +(require '[tablecloth.api.column :refer [column] :as col]) + +;; ### Column creation + +;; We can create an empty column like this: + +(column) + +;; We can check if it it's a column. + +(col/column? (column)) + +;; We can create a columns with data in a number of ways + +(column [1 2 3 4]) + +(column (range 10)) + diff --git a/src/tablecloth/api/column.clj b/src/tablecloth/api/column.clj index 9bbd1d4..8ea95b8 100644 --- a/src/tablecloth/api/column.clj +++ b/src/tablecloth/api/column.clj @@ -4,12 +4,20 @@ [tech.v3.dataset.column :as col] [tech.v3.datatype :as dtype])) - (defn column ([] (col/new-column nil [])) ([data] (column data {:name nil})) ([data {:keys [name]}] - (col/new-column data))) + (col/new-column name data))) + + +(defn column? [item] + (= (class item) tech.v3.dataset.impl.column.Column)) + +(defn zeros [n-zeros] + (column (repeatedly n-zeros (constantly 0)))) +(defn ones [n-ones] + (column (repeatedly n-ones (constantly 1)))) From 04c9b41efc9d23a7bb73cae5678857ee45cd45ba Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sat, 11 Jun 2022 10:33:08 +0300 Subject: [PATCH 04/20] Add typeof function for column --- src/tablecloth/api/column.clj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tablecloth/api/column.clj b/src/tablecloth/api/column.clj index 8ea95b8..e16a5cc 100644 --- a/src/tablecloth/api/column.clj +++ b/src/tablecloth/api/column.clj @@ -21,3 +21,6 @@ (defn ones [n-ones] (column (repeatedly n-ones (constantly 1)))) +(defn typeof [col] + (dtype/elemwise-datatype col)) + From 2eeeee85636cdbda3490f1d35f9a6e494c288899 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sat, 11 Jun 2022 10:33:30 +0300 Subject: [PATCH 05/20] Save work on column exploration doc --- docs/column_exploration.clj | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/column_exploration.clj b/docs/column_exploration.clj index 5a354a6..583cd08 100644 --- a/docs/column_exploration.clj +++ b/docs/column_exploration.clj @@ -11,8 +11,8 @@ [nextjournal.clerk :as clerk])) ^{:kind/hidden true} -(clay/start! {:tools [tools/scittle - tools/clerk]}) +(clay/restart! {:tools [#_tools/scittle + tools/clerk]}) ^{:kind/hidden true} (comment @@ -47,3 +47,32 @@ (column (range 10)) +;; When you do this the types of the resulting array is determined +;; automatically from the items provided. + +(let [int-column (column (range 10))] + (col/typeof int-column)) + +(let [string-column (column ["foo" "bar"])] + (col/typeof string-column)) + +;; ### Basic Operations + +;; Right now we need to use the functional name space from the +;; underlying computation library tech.v3.datatype to operate on +;; columns. + +(require '[tech.v3.datatype.functional :as fun]) + +;; With that imported we can perform a large number of operations: + +(def a (column [20 30 40 50])) +(def b (column (range 4))) + +(fun/- a b) + +(fun/pow a 2) + +(fun/* 10 (fun/sin a)) + +(fun/< a 35) From e5ef8438df435f90689ad0b4b547020a11c50dfb Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sat, 11 Jun 2022 10:33:45 +0300 Subject: [PATCH 06/20] Upgrade to latest clay version --- deps.edn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps.edn b/deps.edn index 5cecffc..81b0f46 100644 --- a/deps.edn +++ b/deps.edn @@ -4,4 +4,4 @@ ;; generateme/fastmath {:mvn/version "2.1.0"} } - :aliases {:dev {:extra-deps {org.scicloj/clay {:mvn/version "1-alpha11"}}}}} + :aliases {:dev {:extra-deps {org.scicloj/clay {:mvn/version "1-alpha14"}}}}} From bcc3582532f0eb83b6a0a9d41a71b0e64179f8f3 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sat, 11 Jun 2022 10:34:28 +0300 Subject: [PATCH 07/20] Save scratch work in column.clj --- src/tablecloth/api/column.clj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tablecloth/api/column.clj b/src/tablecloth/api/column.clj index e16a5cc..585b5e2 100644 --- a/src/tablecloth/api/column.clj +++ b/src/tablecloth/api/column.clj @@ -24,3 +24,13 @@ (defn typeof [col] (dtype/elemwise-datatype col)) + + +(comment + (-> [1 2 3 4] + (col/new-column ) + meta) + + (def b (col/parse-column :string [1 2 3])) + + ) From fb07581439860609ec806510bf27607532980f15 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sat, 11 Jun 2022 11:44:22 +0300 Subject: [PATCH 08/20] Polishing up existing column fns * added some docstrings * re-organized a little --- src/tablecloth/api/column.clj | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/tablecloth/api/column.clj b/src/tablecloth/api/column.clj index 585b5e2..1f70a5e 100644 --- a/src/tablecloth/api/column.clj +++ b/src/tablecloth/api/column.clj @@ -5,32 +5,31 @@ [tech.v3.datatype :as dtype])) (defn column + "Create a `column` from a vector or sequence. " ([] (col/new-column nil [])) ([data] (column data {:name nil})) ([data {:keys [name]}] (col/new-column name data))) +;; Alias for tech.v3.dasetset.column.is-column? +(defn column? + "Return true or false `item` is a column." + [item] + (col/is-column? item)) -(defn column? [item] - (= (class item) tech.v3.dataset.impl.column.Column)) +;; Alias for tech.v3.datatype.elemwise-datatype` +(defn typeof + "Returns the datatype fo the elements within the column `col`." + [col] + (dtype/elemwise-datatype col)) -(defn zeros [n-zeros] +(defn zeros + "Create a new column filled wth `n-zeros`." + [n-zeros] (column (repeatedly n-zeros (constantly 0)))) -(defn ones [n-ones] +(defn ones + "Creates a new column filled with `n-ones`" + [n-ones] (column (repeatedly n-ones (constantly 1)))) - -(defn typeof [col] - (dtype/elemwise-datatype col)) - - - -(comment - (-> [1 2 3 4] - (col/new-column ) - meta) - - (def b (col/parse-column :string [1 2 3])) - - ) From d433c63982dfd218353610c5a68cbb85be1c9426 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Tue, 21 Jun 2022 14:29:23 +0300 Subject: [PATCH 09/20] Move column ns into own domain tablecloth.column.api --- docs/column_exploration.clj | 4 ++-- src/tablecloth/{api/column.clj => column/api.clj} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/tablecloth/{api/column.clj => column/api.clj} (97%) diff --git a/docs/column_exploration.clj b/docs/column_exploration.clj index 583cd08..fa405b8 100644 --- a/docs/column_exploration.clj +++ b/docs/column_exploration.clj @@ -11,7 +11,7 @@ [nextjournal.clerk :as clerk])) ^{:kind/hidden true} -(clay/restart! {:tools [#_tools/scittle +#_(clay/restart! {:tools [#_tools/scittle tools/clerk]}) ^{:kind/hidden true} @@ -29,7 +29,7 @@ ;; ## Usage -(require '[tablecloth.api.column :refer [column] :as col]) +(require '[tablecloth.column.api :refer [column] :as col]) ;; ### Column creation diff --git a/src/tablecloth/api/column.clj b/src/tablecloth/column/api.clj similarity index 97% rename from src/tablecloth/api/column.clj rename to src/tablecloth/column/api.clj index 1f70a5e..f503585 100644 --- a/src/tablecloth/api/column.clj +++ b/src/tablecloth/column/api.clj @@ -1,4 +1,4 @@ -(ns tablecloth.api.column +(ns tablecloth.column.api (:refer-clojure :exclude [group-by]) (:require [tech.v3.dataset :as ds] [tech.v3.dataset.column :as col] From 6a08d61704b738a878cd0da9da13c5f6d1dfa6bf Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Tue, 21 Jun 2022 15:34:48 +0300 Subject: [PATCH 10/20] Add tests for `tablecloth.column.api/column` --- test/tablecloth/column/api_test.clj | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/tablecloth/column/api_test.clj diff --git a/test/tablecloth/column/api_test.clj b/test/tablecloth/column/api_test.clj new file mode 100644 index 0000000..3530981 --- /dev/null +++ b/test/tablecloth/column/api_test.clj @@ -0,0 +1,12 @@ +(ns tablecloth.column.api-test + (:require [tablecloth.column.api :as api] + [midje.sweet :refer [fact =>]])) + +(fact "`column` returns a column" + (tech.v3.dataset.column/is-column? (api/column)) => true) + +(fact "`column` provides a few ways to generate a column`" + (api/column) => [] + (api/column [1 2 3]) => [1 2 3] + (api/column (list 1 2 3)) =>[1 2 3] + (api/column (range 3)) => [0 1 2]) From 186e7643e0a05a24fdc8398310806b72c6016559 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Tue, 21 Jun 2022 15:49:39 +0300 Subject: [PATCH 11/20] Add tests for `zeros` and `ones` --- test/tablecloth/column/api_test.clj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/tablecloth/column/api_test.clj b/test/tablecloth/column/api_test.clj index 3530981..ecd7a2e 100644 --- a/test/tablecloth/column/api_test.clj +++ b/test/tablecloth/column/api_test.clj @@ -10,3 +10,9 @@ (api/column [1 2 3]) => [1 2 3] (api/column (list 1 2 3)) =>[1 2 3] (api/column (range 3)) => [0 1 2]) + +(fact "`zeros` returns a column filled with zeros" + (api/zeros 3) => [0 0 0]) + +(fact "`ones` returns a column filled with ones" + (api/ones 3) => [1 1 1]) From 851819f0d47e53d253b36cdba702d3477c22f110 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Tue, 21 Jun 2022 18:53:05 +0300 Subject: [PATCH 12/20] Use api template to write public api --- src/tablecloth/column/api.clj | 47 ++++++++++++---------- src/tablecloth/column/api/api_template.clj | 20 +++++++++ src/tablecloth/column/api/column.clj | 35 ++++++++++++++++ 3 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 src/tablecloth/column/api/api_template.clj create mode 100644 src/tablecloth/column/api/column.clj diff --git a/src/tablecloth/column/api.clj b/src/tablecloth/column/api.clj index f503585..53d6a8e 100644 --- a/src/tablecloth/column/api.clj +++ b/src/tablecloth/column/api.clj @@ -1,35 +1,40 @@ (ns tablecloth.column.api - (:refer-clojure :exclude [group-by]) - (:require [tech.v3.dataset :as ds] - [tech.v3.dataset.column :as col] - [tech.v3.datatype :as dtype])) + ;;Autogenerated from tablecloth.column.api.api-template-- DO NOT EDIT + "Tablecloth Column API" + (:require [tablecloth.column.api.api-template] + [tablecloth.column.api.column])) (defn column "Create a `column` from a vector or sequence. " - ([] (col/new-column nil [])) + ([] + (tablecloth.column.api.column/column )) ([data] - (column data {:name nil})) - ([data {:keys [name]}] - (col/new-column name data))) + (tablecloth.column.api.column/column data)) + ([data options] + (tablecloth.column.api.column/column data options))) -;; Alias for tech.v3.dasetset.column.is-column? -(defn column? + +(defn column? "Return true or false `item` is a column." - [item] - (col/is-column? item)) + ([item] + (tablecloth.column.api.column/column? item))) + + +(defn ones + "Creates a new column filled with `n-ones`" + ([n-ones] + (tablecloth.column.api.column/ones n-ones))) + -;; Alias for tech.v3.datatype.elemwise-datatype` (defn typeof "Returns the datatype fo the elements within the column `col`." - [col] - (dtype/elemwise-datatype col)) + ([col] + (tablecloth.column.api.column/typeof col))) + (defn zeros "Create a new column filled wth `n-zeros`." - [n-zeros] - (column (repeatedly n-zeros (constantly 0)))) + ([n-zeros] + (tablecloth.column.api.column/zeros n-zeros))) + -(defn ones - "Creates a new column filled with `n-ones`" - [n-ones] - (column (repeatedly n-ones (constantly 1)))) diff --git a/src/tablecloth/column/api/api_template.clj b/src/tablecloth/column/api/api_template.clj new file mode 100644 index 0000000..e197ce7 --- /dev/null +++ b/src/tablecloth/column/api/api_template.clj @@ -0,0 +1,20 @@ +(ns tablecloth.column.api.api-template + "Tablecloth Column API" + (:require [tech.v3.datatype.export-symbols :as exporter])) + +(exporter/export-symbols tablecloth.column.api.column + column + column? + typeof + zeros + ones + ) + +(comment + (exporter/write-api! 'tablecloth.column.api.api-template + 'tablecloth.column.api + "src/tablecloth/column/api.clj" + '[] + ) + + ) diff --git a/src/tablecloth/column/api/column.clj b/src/tablecloth/column/api/column.clj new file mode 100644 index 0000000..90dee86 --- /dev/null +++ b/src/tablecloth/column/api/column.clj @@ -0,0 +1,35 @@ +(ns tablecloth.column.api.column + (:require [tech.v3.dataset.column :as col] + [tech.v3.datatype :as dtype])) + +(defn column + "Create a `column` from a vector or sequence. " + ([] + (col/new-column nil [])) + ([data] + (column data {:name nil})) + ([data {:keys [name] + :as options}] + (col/new-column name data))) + +;; Alias for tech.v3.dasetset.column.is-column? +(defn column? + "Return true or false `item` is a column." + [item] + (col/is-column? item)) + +;; Alias for tech.v3.datatype.elemwise-datatype` +(defn typeof + "Returns the datatype fo the elements within the column `col`." + [col] + (dtype/elemwise-datatype col)) + +(defn zeros + "Create a new column filled wth `n-zeros`." + [n-zeros] + (column (repeatedly n-zeros (constantly 0)))) + +(defn ones + "Creates a new column filled with `n-ones`" + [n-ones] + (column (repeatedly n-ones (constantly 1)))) From 1d2cef3d463ce970782514c25adb1d7f18e151a9 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sat, 25 Jun 2022 23:18:50 +0300 Subject: [PATCH 13/20] Write tests against `tablecloth.column.api.column` ns --- test/tablecloth/column/api/column_test.clj | 18 ++++++++++++++++++ test/tablecloth/column/api_test.clj | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 test/tablecloth/column/api/column_test.clj delete mode 100644 test/tablecloth/column/api_test.clj diff --git a/test/tablecloth/column/api/column_test.clj b/test/tablecloth/column/api/column_test.clj new file mode 100644 index 0000000..4ee8788 --- /dev/null +++ b/test/tablecloth/column/api/column_test.clj @@ -0,0 +1,18 @@ +(ns tablecloth.column.api.column-test + (:require [tablecloth.column.api.column :refer [column zeros ones]] + [midje.sweet :refer [fact =>]])) + +(fact "`column` returns a column" + (tech.v3.dataset.column/is-column? (column)) => true) + +(fact "`column` provides a few ways to generate a column`" + (column) => [] + (column [1 2 3]) => [1 2 3] + (column (list 1 2 3)) =>[1 2 3] + (column (range 3)) => [0 1 2]) + +(fact "`zeros` returns a column filled with zeros" + (zeros 3) => [0 0 0]) + +(fact "`ones` returns a column filled with ones" + (ones 3) => [1 1 1]) diff --git a/test/tablecloth/column/api_test.clj b/test/tablecloth/column/api_test.clj deleted file mode 100644 index ecd7a2e..0000000 --- a/test/tablecloth/column/api_test.clj +++ /dev/null @@ -1,18 +0,0 @@ -(ns tablecloth.column.api-test - (:require [tablecloth.column.api :as api] - [midje.sweet :refer [fact =>]])) - -(fact "`column` returns a column" - (tech.v3.dataset.column/is-column? (api/column)) => true) - -(fact "`column` provides a few ways to generate a column`" - (api/column) => [] - (api/column [1 2 3]) => [1 2 3] - (api/column (list 1 2 3)) =>[1 2 3] - (api/column (range 3)) => [0 1 2]) - -(fact "`zeros` returns a column filled with zeros" - (api/zeros 3) => [0 0 0]) - -(fact "`ones` returns a column filled with ones" - (api/ones 3) => [1 1 1]) From c81d13cb21e474390b5a71fa6585ec8723341dbd Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sun, 26 Jun 2022 11:06:11 +0300 Subject: [PATCH 14/20] Add column exploration html --- docs/column_exploration.html | 3742 ++++++++++++++++++++++++++++++++++ 1 file changed, 3742 insertions(+) create mode 100644 docs/column_exploration.html diff --git a/docs/column_exploration.html b/docs/column_exploration.html new file mode 100644 index 0000000..5b36441 --- /dev/null +++ b/docs/column_exploration.html @@ -0,0 +1,3742 @@ + + + + + +
column_exploration

Tablecloth Column Exploration

What is this exploration?

We want to add a column entity to tablecloth that parallels dataset. It will make the column a first-class entity within tablecloth.

Usage

(require '[tablecloth.column.api :refer [column] :as col])
nil
+

Column creation

We can create an empty column like this:

(column)
#tech.v3.dataset.column[0]
+null
+[]
+

We can check if it it's a column.

(col/column? (column))
true
+

We can create a columns with data in a number of ways

(column [1 2 3 4])
#tech.v3.dataset.column[4]
+null
+[1, 2, 3, 4]
+
(column (range 10))
#tech.v3.dataset.column[10]
+null
+[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+

When you do this the types of the resulting array is determined automatically from the items provided.

(let [int-column (column (range 10))]
+  (col/typeof int-column))
:int64
+
(let [string-column (column ["foo" "bar"])]
+  (col/typeof string-column))
:string
+

Basic Operations

Right now we need to use the functional name space from the underlying computation library tech.v3.datatype to operate on columns.

(require '[tech.v3.datatype.functional :as fun])
nil
+

With that imported we can perform a large number of operations:

(def a (column [20 30 40 50]))
#'intro/a
+
(def b (column (range 4)))
#'intro/b
+
(fun/- a b)
#array-buffer[4]
+[20, 29, 38, 47]
+
(fun/pow a 2)
#array-buffer[4]
+[400.0, 900.0, 1600, 2500]
+
(fun/* 10 (fun/sin a))
#array-buffer[4]
+[9.129, -9.880, 7.451, -2.624]
+
(fun/< a 35)
#array-buffer[4]
+[true, true, false, false]
+
\ No newline at end of file From 2788e3efb55aff58ebeb76174391f9ed52910984 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sun, 26 Jun 2022 11:44:17 +0300 Subject: [PATCH 15/20] Add `typeof?` function to check datatype of column els --- src/tablecloth/column/api/column.clj | 5 +++++ test/tablecloth/column/api/column_test.clj | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/tablecloth/column/api/column.clj b/src/tablecloth/column/api/column.clj index 90dee86..d983a9c 100644 --- a/src/tablecloth/column/api/column.clj +++ b/src/tablecloth/column/api/column.clj @@ -24,6 +24,11 @@ [col] (dtype/elemwise-datatype col)) +(defn typeof? + "True|false the column's elements are of type `dtype`" + [col dtype] + (= (dtype/elemwise-datatype col) dtype)) + (defn zeros "Create a new column filled wth `n-zeros`." [n-zeros] diff --git a/test/tablecloth/column/api/column_test.clj b/test/tablecloth/column/api/column_test.clj index 4ee8788..b7f4c92 100644 --- a/test/tablecloth/column/api/column_test.clj +++ b/test/tablecloth/column/api/column_test.clj @@ -1,5 +1,5 @@ (ns tablecloth.column.api.column-test - (:require [tablecloth.column.api.column :refer [column zeros ones]] + (:require [tablecloth.column.api.column :refer [column zeros ones typeof?]] [midje.sweet :refer [fact =>]])) (fact "`column` returns a column" @@ -11,6 +11,21 @@ (column (list 1 2 3)) =>[1 2 3] (column (range 3)) => [0 1 2]) +(fact "`column` identifies the type of the elements automatically" + (-> [1 2 3] + (column) + (tech.v3.datatype/elemwise-datatype)) => :int64 + (-> [true false true] + (column) + (tech.v3.datatype/elemwise-datatype)) => :boolean + (-> [1 true false] + (column) + (tech.v3.datatype/elemwise-datatype)) => :object) + +(fact "we can check the type of a column's elements with `typeof?`" + (typeof? (column [1 2 3]) :int64) => true + (typeof? (column [true false]) :boolean) => true) + (fact "`zeros` returns a column filled with zeros" (zeros 3) => [0 0 0]) From 14ca93556399e9f828ebd3b8182ccb253e6b6926 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Tue, 5 Jul 2022 11:29:34 +0300 Subject: [PATCH 16/20] Use buffer when creating zeros & ones columns --- src/tablecloth/column/api/column.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tablecloth/column/api/column.clj b/src/tablecloth/column/api/column.clj index d983a9c..6b93d27 100644 --- a/src/tablecloth/column/api/column.clj +++ b/src/tablecloth/column/api/column.clj @@ -1,6 +1,6 @@ (ns tablecloth.column.api.column (:require [tech.v3.dataset.column :as col] - [tech.v3.datatype :as dtype])) + [tech.v3.datatype :refer [emap]])) (defn column "Create a `column` from a vector or sequence. " @@ -32,9 +32,9 @@ (defn zeros "Create a new column filled wth `n-zeros`." [n-zeros] - (column (repeatedly n-zeros (constantly 0)))) + (column (emap (constantly 0) :int64 (range n-zeros)))) (defn ones "Creates a new column filled with `n-ones`" [n-ones] - (column (repeatedly n-ones (constantly 1)))) + (column (emap (constantly 1) :int64 (range n-ones)))) From 2d1d07ebf30bb0053df68319491b541b84cffe38 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Tue, 5 Jul 2022 12:03:44 +0300 Subject: [PATCH 17/20] Use `dtype` alias in ns --- src/tablecloth/column/api/column.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tablecloth/column/api/column.clj b/src/tablecloth/column/api/column.clj index 6b93d27..f648b21 100644 --- a/src/tablecloth/column/api/column.clj +++ b/src/tablecloth/column/api/column.clj @@ -1,6 +1,6 @@ (ns tablecloth.column.api.column (:require [tech.v3.dataset.column :as col] - [tech.v3.datatype :refer [emap]])) + [tech.v3.datatype :as dtype])) (defn column "Create a `column` from a vector or sequence. " @@ -32,9 +32,9 @@ (defn zeros "Create a new column filled wth `n-zeros`." [n-zeros] - (column (emap (constantly 0) :int64 (range n-zeros)))) + (column (dtype/emap (constantly 0) :int64 (range n-zeros)))) (defn ones "Creates a new column filled with `n-ones`" [n-ones] - (column (emap (constantly 1) :int64 (range n-ones)))) + (column (dtype/emap (constantly 1) :int64 (range n-ones)))) From e5c8322aba36a97fd01e8cc61dd55d252ab657c5 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Tue, 5 Jul 2022 12:05:06 +0300 Subject: [PATCH 18/20] Add comment to code snippet generating column api --- src/tablecloth/column/api/api_template.clj | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/tablecloth/column/api/api_template.clj b/src/tablecloth/column/api/api_template.clj index e197ce7..411a6f4 100644 --- a/src/tablecloth/column/api/api_template.clj +++ b/src/tablecloth/column/api/api_template.clj @@ -11,10 +11,9 @@ ) (comment + // Use this to generate the column api (exporter/write-api! 'tablecloth.column.api.api-template 'tablecloth.column.api "src/tablecloth/column/api.clj" - '[] - ) - - ) + '[]) + ,) From e42a3d91d0f097811af0725a1122da03043c6136 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Tue, 5 Jul 2022 12:05:46 +0300 Subject: [PATCH 19/20] Fix comment syntax --- src/tablecloth/column/api/api_template.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tablecloth/column/api/api_template.clj b/src/tablecloth/column/api/api_template.clj index 411a6f4..4ceedbd 100644 --- a/src/tablecloth/column/api/api_template.clj +++ b/src/tablecloth/column/api/api_template.clj @@ -11,7 +11,7 @@ ) (comment - // Use this to generate the column api + ;; Use this to generate the column api (exporter/write-api! 'tablecloth.column.api.api-template 'tablecloth.column.api "src/tablecloth/column/api.clj" From 35ec1063c616eb5b4cc4baeb75826636939b51f9 Mon Sep 17 00:00:00 2001 From: Ethan Miller Date: Sun, 17 Jul 2022 19:02:18 +0300 Subject: [PATCH 20/20] Use `tech.v3.datatype/const-reader` for `zeros` and `ones` function --- src/tablecloth/column/api/column.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tablecloth/column/api/column.clj b/src/tablecloth/column/api/column.clj index f648b21..5fcaf56 100644 --- a/src/tablecloth/column/api/column.clj +++ b/src/tablecloth/column/api/column.clj @@ -32,9 +32,9 @@ (defn zeros "Create a new column filled wth `n-zeros`." [n-zeros] - (column (dtype/emap (constantly 0) :int64 (range n-zeros)))) + (column (dtype/const-reader 0 n-zeros))) (defn ones "Creates a new column filled with `n-ones`" [n-ones] - (column (dtype/emap (constantly 1) :int64 (range n-ones)))) + (column (dtype/const-reader 1 n-ones)))