PrettyTables for 2-dimensional KeyedArrays
I am seeking a table that looks more like the REPL display of the KeyedArray, rather than stacking it into a DataFrame-style format. Is that possible?
using RectiGrids, AxisKeys, PrettyTables
julia> grid('a':'c', 'A':'C')
2-dimensional KeyedArray(...) with keys:
↓ 3-element StepRange{Char,...}
→ 3-element StepRange{Char,...}
And data, 3×3 RectiGrids.RectiGridArr{Base.OneTo(2), Tuple{Char, Char}, 2, Tuple{Nothing, Nothing}, Tuple{StepRange{Char, Int64}, StepRange{Char, Int64}}}:
('A') ('B') ('C')
('a') ('a', 'A') ('a', 'B') ('a', 'C')
('b') ('b', 'A') ('b', 'B') ('b', 'C')
('c') ('c', 'A') ('c', 'B') ('c', 'C')
julia> pretty_table(grid('a':'c', 'A':'C'))
┌───────┬───────┬────────────┐
│ dim_1 │ dim_2 │ value │
├───────┼───────┼────────────┤
│ a │ A │ ('a', 'A') │
│ b │ A │ ('b', 'A') │
│ c │ A │ ('c', 'A') │
│ a │ B │ ('a', 'B') │
│ b │ B │ ('b', 'B') │
│ c │ B │ ('c', 'B') │
│ a │ C │ ('a', 'C') │
│ b │ C │ ('b', 'C') │
│ c │ C │ ('c', 'C') │
└───────┴───────┴────────────┘
Hi @jariji !
Not easily! KeyedArray returns the following Tables:
julia> Tables.columns(a)
(dim_1 = ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c'], dim_2 = ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'], value = [('a', 'A'), ('b', 'A'), ('c', 'A'), ('a', 'B'), ('b', 'B'), ('c', 'B'), ('a', 'C'), ('b', 'C'), ('c', 'C')])
Hence, it is saying to PrettyTables that it is a table with three columns. I am not sure how we can support this kind of construction.
I think the way to deal with this would be to use a package extension and specialise for KeyedArray
Hi @frankier !
I do not agree. Otherwise we will have a HUGE number of extensions to handle each and every package. We really must support only Tables.jl interface except from very few native types (like Array).