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

Unexpected behavior for row table #61

Closed
ablaom opened this issue Apr 28, 2022 · 8 comments · Fixed by #63
Closed

Unexpected behavior for row table #61

ablaom opened this issue Apr 28, 2022 · 8 comments · Fixed by #63
Labels
bug Something isn't working

Comments

@ablaom
Copy link
Contributor

ablaom commented Apr 28, 2022

I expected this:

julia> X = Tables.table(rand(10, 3))
Tables.MatrixTable{Matrix{Float64}} with 10 rows, 3 columns, and schema:
 :Column1  Float64
 :Column2  Float64
 :Column3  Float64

julia> rt = Tables.rowtable(X)
10-element Vector{NamedTuple{(:Column1, :Column2, :Column3), Tuple{Float64, Float64, Float64}}}:
 (Column1 = 0.5565428815102202, Column2 = 0.9460318649319521, Column3 = 0.3359377652605777)
 (Column1 = 0.5075982188653294, Column2 = 0.18315493443083453, Column3 = 0.9682078694091394)
 (Column1 = 0.9963268867042159, Column2 = 0.9329899214178856, Column3 = 0.5470116730645322)
 (Column1 = 0.3586863538486338, Column2 = 0.028403436910423796, Column3 = 0.37539265155858015)
 (Column1 = 0.6219233944778164, Column2 = 0.3499360310552866, Column3 = 0.14038853850080102)
 (Column1 = 0.587164895366161, Column2 = 0.9365631957076301, Column3 = 0.4638888590010579)
 (Column1 = 0.5896922517858991, Column2 = 0.29876303863960274, Column3 = 0.8361667225744209)
 (Column1 = 0.3924751962812454, Column2 = 0.7981085942387889, Column3 = 0.11151780408924594)
 (Column1 = 0.26805907763502645, Column2 = 0.6863527449570381, Column3 = 0.5322558300965325)
 (Column1 = 0.4000480227789831, Column2 = 0.5888482501962962, Column3 = 0.25538366367233634)

julia> X |> Center()
(Column1 = [0.02869116358486712, -0.020253499060023716, 0.46847516877886275, -0.16916536407671934, 0.09407167655246329, 0.059313177440807885, 0.061840533860546, -0.13537652164410774, -0.25979264029032667, -0.12780369514637002], Column2 = [0.37111666368337826, -0.39176026681773934, 0.35807472016931174, -0.5465117643381501, -0.22497917019328728, 0.36164799445905627, -0.27615216260897113, 0.223193392990215, 0.11143754370846426, 0.013933048947722293], Column3 = [-0.12067737246214477, 0.5115927316864168, 0.09039653534180975, -0.08122248616414235, -0.3162265992219215, 0.007273721278335421, 0.37955158485169843, -0.34509733363347656, 0.07564069237381005, -0.20123147405038616])

But not this:

julia> rt |> Center()
NamedTuple{(), Tuple{}}[]
@ablaom ablaom changed the title Unexpected behavior centering a row table Unexpected behavior for row table Apr 28, 2022
@ablaom
Copy link
Contributor Author

ablaom commented Apr 28, 2022

julia> rt |> Select(1, 3)
ERROR: BoundsError: attempt to access 0-element Vector{Union{}} at index [[1, 3]]
Stacktrace:

Mmm. What am I missing here?

@juliohm
Copy link
Member

juliohm commented Apr 28, 2022

The issue with Center is probably because of the annoying fact that Tables.columnnames(rt) returns empty tuple for row-tables. The columnnames trait only works with column-tables. We need to first convert to Tables.columntable before proceeding with the implementation I guess?

The issue with Select may be related to the same trait. @eliascarv can you take a look at this?

@juliohm juliohm added the bug Something isn't working label Apr 28, 2022
@juliohm
Copy link
Member

juliohm commented Apr 28, 2022

We should also add a lot of tests with row tables to make sure that we are not missing other issues before v1.0.

@ablaom
Copy link
Contributor Author

ablaom commented Apr 28, 2022

Dictionary row tables also cannot be Centered or Selected:

julia> drt = Tables.dictrowtable(X);

julia> drt |> Center()
ERROR: type NamedTuple has no field names

julia> drt |> Center()
ERROR: type NamedTuple has no field names

@eliascarv
Copy link
Member

eliascarv commented Apr 29, 2022

I think the problem is in the way we are using the Tables.columnnames function.
This is the current code:

names = Tables.columnnames(table)

But this is the correct way:

cols = Tables.columns(table)
names = Tables.columnnames(cols)

@eliascarv
Copy link
Member

I will do a PR to fix this problem.

@ablaom
Copy link
Contributor Author

ablaom commented May 1, 2022

@eliascarv @juliohm Thanks for addressing this so quickly ❤️

@eliascarv
Copy link
Member

You are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants