pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
27.51k stars 1.68k forks source link

Allow easy conversion between structs and DataFrames #15709

Open andyquinterom opened 2 months ago

andyquinterom commented 2 months ago

Description

A problem I usually have is being able to easily convert between a Vec<T> and a DataFrame or any iterator to a dataframe.

I built this small crate with a proc macro that makes this much easier.

https://crates.io/crates/polars-row-derive

Could this be built into polars, perhaps behind a feature flag?

This could be quite cool to make certain work flows much faster.

msberk commented 1 month ago

@andyquinterom Thanks for this - I was kind of amazed not to find this functionality built in as it seems like a fundamental operation. It caught me off guard that I couldn't go from a Vec<T> returned by SQLx to a dataframe without some kind of builder gymnastics or a bunch of boilerplate.

Maybe arguable if this produces the most efficient conversion but I don't really care - better to have it than not, and now at least I know your crate exists! Would love to see something like this built into the Polars distribution.