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

let-dataset .. and more ? #111

Open
awb99 opened this issue Sep 6, 2023 · 4 comments
Open

let-dataset .. and more ? #111

awb99 opened this issue Sep 6, 2023 · 4 comments

Comments

@awb99
Copy link

awb99 commented Sep 6, 2023

Just found out about let-dataset ... great feature. Now perhaps you want to expa d let-dataset by adding add-colums-let .. same macro but it will get a dataset to operate on as first parameter ... the second parameter is unchanged (the vector of let bindings). What it will do is create a binding of all column names (so keyword to symbol mapping) so that they can be used in the binding. And second it will add all binding names to columns (similar to how it is done in let-dataset

; make ds1 .. with x y z columns
(def ds1
(tc/let-dataset [x (range 1 6)
y 1
z (dfn/+ x y)]))

; add a column to ds1
; note x y are the :x :y columns in the dataset
(tc/add-columns-let ds1 [a (dfn/+ x y)])

@awb99
Copy link
Author

awb99 commented Sep 6, 2023

This is my current approach:

https://github.com/clojure-quant/techml.vector-math/blob/main/test/syntax.clj

(s/calc d [x (+ a b)
y (+ x c)
z [y 1]
])
This is the macro that adds bindings to all columns in the dataset:
https://github.com/clojure-quant/techml.vector-math/blob/main/src/cquant/vmath/syntax/column.clj

@awb99
Copy link
Author

awb99 commented Sep 6, 2023

My goal is to be able to enter vector math in a format that has identical syntax to a scalar only math. So (* a b) in vector mode means (let [a (:a ds1) b (:b ds1)] (dfn/* a b)) or in scalar mode just (let [a 1 b 2] (* a b)). I feel such math is better placed in tablecloth.

@genmeblog
Copy link
Member

Generally there is a subproject by @ezmiller which lifts all columnar / vector operations to its own namespace.

I think there is a space for a macro you've proposed. The only change would be explicit column accessor, column name can be anything, not only keywords.

(tc/let-add-columns ds [a :a b :b z (dfn/+ a b)])

@genmeblog
Copy link
Member

or maybe add one more arity to let-dataset?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants