jacobadenbaum / TexTables.jl

Publication quality regression and statistical tables
Other
38 stars 7 forks source link

Remap column headers in vcat #33

Closed pearlzli closed 1 year ago

pearlzli commented 2 years ago

Hey Jacob! This is the first of two pull requests about creating composite tables. Suppose we start with:

using TexTables

m, n = 5, 4
keys = ["x$i" for i in 1:m]
cols = map(j -> TableCol("test$j", keys, rand(m)), 1:n)

This pull request adds column header remapping to vcat. hcat already does this:

julia> t1 = hcat(cols...);

julia> t1.col_index == [col.header for col in t1.columns]
true

However, for vcat, the column index doesn't match the column headers, so that subsequent calls to hcat and join_table throw errors:

julia> t2 = vcat(cols...);

julia> t2.col_index
4-element Vector{TexTables.TableIndex{1}}:
 TexTables.TableIndex{1}((1,), (:test1,))
 TexTables.TableIndex{1}((2,), (:test2,))
 TexTables.TableIndex{1}((3,), (:test3,))
 TexTables.TableIndex{1}((4,), (:test4,))

julia> [col.header for col in t2.columns]
4-element Vector{TexTables.TableIndex{1}}:
 TexTables.TableIndex{1}((1,), (:test1,))
 TexTables.TableIndex{1}((1,), (:test2,))
 TexTables.TableIndex{1}((1,), (:test3,))
 TexTables.TableIndex{1}((1,), (:test4,))

julia> hcat(t1, t2)
ERROR: KeyError: key TexTables.TableIndex{1}((1,), (:test2,)) not found

julia> join_table(t1, t2)
ERROR: KeyError: key TexTables.TableIndex{1}((1,), (:test2,)) not found

Under the new behavior, t2.col_index should match [col.header for col in t2.columns].

jacobadenbaum commented 2 years ago

hey pearl! I'm sorry I missed the notification about this. I will take a look at these PRs shortly (probably tomorrow!)

I see that tests are failing on julia 1.0, but the errors are kind of weird. I want to figure out what's going wrong, but my guess is that it's not something to do with this PR.