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

Tables.columnnames(Z) after Z = Tables.rowtable(X) or Z = Tables.dictrowtable(X) does not return proper column names #338

Open
EssamWisam opened this issue Jul 15, 2023 · 2 comments

Comments

@EssamWisam
Copy link

EssamWisam commented Jul 15, 2023

For instance,

X = DataFrame(rand(Float64, 4, 2), :auto)

X_row = Tables.rowtable(X)
println(Tables.columnnames(X_row))

X_dict_row = Tables.dictrowtable(X)
println(Tables.columnnames(X_dict_row))

X_col = Tables.columntable(X)
println(Tables.columnnames(X_col))

yields

()
(:names, :types, :values)
(:x1, :x2)

I wonder if anything is wrong with this, I expected all to return (:x1, :x2). It crossed my mind that this could be an issue due to the source being a dataframe but I also tried a matrix table for X.

Thanks for this wonderful package!

@bkamins
Copy link
Member

bkamins commented Jul 15, 2023

see also #337.

@quinnj - I understand that for these types and for CSV.File a special method for Tables.columnnames should be added?

@EssamWisam
Copy link
Author

It resolves my issue if I do

using DataFrames
using Tables

X = DataFrame(rand(Float64, 4, 2), :auto)

X_row = Tables.columns(Tables.rowtable(X))
println(Tables.columnnames(X_row))

X_dict_row = Tables.columns(Tables.dictrowtable(X))
println(Tables.columnnames(X_dict_row))

X_col = Tables.columntable(X)
println(Tables.columnnames(X_col))

After going through the docs, a table may only define one of Tables.columnnames(Table) or Tables.columnnames(row). Doesn't it seems natural for one to assume that the former should work for any table? In all cases, I wonder if one can know in advance whether they should do Tables.columnnames(Table) or Tables.columnnames(row) (i.e., whether the tables implements Tables.rows or Tables.columns)

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