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

PrettyTables for 2-dimensional KeyedArrays #243

Open
jariji opened this issue May 12, 2024 · 3 comments
Open

PrettyTables for 2-dimensional KeyedArrays #243

jariji opened this issue May 12, 2024 · 3 comments

Comments

@jariji
Copy link
Contributor

jariji commented May 12, 2024

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') │
└───────┴───────┴────────────┘
@ronisbr
Copy link
Owner

ronisbr commented May 12, 2024

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.

@frankier
Copy link

I think the way to deal with this would be to use a package extension and specialise for KeyedArray

@ronisbr
Copy link
Owner

ronisbr commented Aug 27, 2024

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).

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

3 participants