table icon indicating copy to clipboard operation
table copied to clipboard

feature request: default implementation for list of structs

Open skyqrose opened this issue 6 months ago • 3 comments

I have a list of structs representing row-major tabular data that I want to satisfy the Table protocol so that I can pass them to Explorer.DataFrame.new().

This is almost automatically works, except that it's specifically disabled for struct rows (but not map rows) in init_row(): https://github.com/elixir-ecto/table/blob/5704327dfaeb8dce0dd731aa2996e731f6e869c6/lib/table/reader/enumerable.ex#L54-L56

Having a tabular data as a list of structs seems like it should be common case. Should this library support it?

A workaround would be to define my own custom implementation of the protocol. I can't define an implementation for List because it's already defined, and I don't want to overwrite the default in all cases, just for lists of structs. But I guess I could define a new struct that wraps the list, and then define the implementation for that.

My ideal implementation would keep the column order from the struct definition, instead of sorting the keys like it does for maps.

skyqrose avatar Jun 26 '25 20:06 skyqrose