JuliaParallel / DTables.jl

Distributed table structures and data manipulation operations built on top of Dagger.jl
MIT License
73 stars 4 forks source link

Add PrettyTables rendering for GDTable #48

Open harsharora21 opened 1 year ago

harsharora21 commented 1 year ago

As suggested by @krynju, This PR adds PrettyTables rendering for GDTable

Example

julia> dt = DTable((a=[0,1,2,0,1,2,0,0,1,1], b=[0,1,2,3,4,5,6,7,8,9]), 10);

julia> gdt = groupby(dt, :a);

julia> print(gdt)
GDTable with 3 partitions and 3 keys
Tabletype: NamedTuple
Grouped by: [:a]
┌───────┬───────┐
│     a │     b │
│ Int64 │ Int64 │
├───────┼───────┤
│     0 │     0 │
│     0 │     3 │
│     0 │     6 │
│     0 │     7 │
│     2 │     2 │
│     2 │     5 │
│     1 │     1 │
│     1 │     4 │
│     1 │     8 │
│     1 │     9 │
└───────┴───────┘
krynju commented 1 year ago

could you try getting an effect like this? when you iterate a gdtable you should be getting dtable type elements so should be fairly easy DataFrames code could be a hint as well

image

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage has no change and project coverage change: -3.01% :warning:

Comparison is base (94d66ed) 95.47% compared to head (cd4c64c) 92.46%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #48 +/- ## ========================================== - Coverage 95.47% 92.46% -3.01% ========================================== Files 12 12 Lines 861 889 +28 ========================================== Hits 822 822 - Misses 39 67 +28 ``` | [Files Changed](https://app.codecov.io/gh/JuliaParallel/DTables.jl/pull/48?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaParallel) | Coverage Δ | | |---|---|---| | [src/table/gdtable.jl](https://app.codecov.io/gh/JuliaParallel/DTables.jl/pull/48?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaParallel#diff-c3JjL3RhYmxlL2dkdGFibGUuamw=) | `51.72% <0.00%> (-24.55%)` | :arrow_down: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

harsharora21 commented 1 year ago

Newer commit makes it more like dataframe.

Example

Create a sample table

julia> dt = DTable((a=[0,1,2,0,1,2,0,0,1,1], b=[0,1,2,3,4,5,6,7,8,9]), 10);

Groupby without function

julia> gdt = groupby(dt, :a);

julia> gdt #limited printing
GDTable with 3 partitions and 3 keys
Tabletype: NamedTuple
Grouped by: [:a]
First Group (4 rows): a = 0
┌───┬───┐
│ a │ b │
├───┼───┤
│ 0 │ 0 │
│ 0 │ 3 │
│ 0 │ 6 │
│ 0 │ 7 │
└───┴───┘
⋮
Last Group (2 rows): a = 2
┌───┬───┐
│ a │ b │
├───┼───┤
│ 2 │ 2 │
│ 2 │ 5 │
└───┴───┘

julia> print(gdt)
GDTable with 3 partitions and 3 keys
Tabletype: NamedTuple
Grouped by: [:a]
Group 1 (4 rows): a = 0
┌───┬───┐
│ a │ b │
├───┼───┤
│ 0 │ 0 │
│ 0 │ 3 │
│ 0 │ 6 │
│ 0 │ 7 │
└───┴───┘
Group 2 (4 rows): a = 1
┌───┬───┐
│ a │ b │
├───┼───┤
│ 1 │ 1 │
│ 1 │ 4 │
│ 1 │ 8 │
│ 1 │ 9 │
└───┴───┘
Group 3 (2 rows): a = 2
┌───┬───┐
│ a │ b │
├───┼───┤
│ 2 │ 2 │
│ 2 │ 5 │
└───┴───┘

Groupby with function

julia> function rowsum(row)
           return row.a + row.b
       end
rowsum (generic function with 1 method)

julia> gdt = groupby(dt, rowsum);

julia> gdt #limited printing
GDTable with 9 partitions and 9 keys
Tabletype: NamedTuple
Grouped by: rowsum
First Group (1 rows): Function rowsum = 0
┌───┬───┐
│ a │ b │
├───┼───┤
│ 0 │ 0 │
└───┴───┘
⋮
Last Group (1 rows): Function rowsum = 10
┌───┬───┐
│ a │ b │
├───┼───┤
│ 1 │ 9 │
└───┴───┘

julia> print(gdt)
GDTable with 9 partitions and 9 keys
Tabletype: NamedTuple
Grouped by: rowsum
Group 1 (1 rows): Function rowsum = 0
┌───┬───┐
│ a │ b │
├───┼───┤
│ 0 │ 0 │
└───┴───┘
Group 2 (1 rows): Function rowsum = 2
┌───┬───┐
│ a │ b │
├───┼───┤
│ 1 │ 1 │
└───┴───┘
Group 3 (1 rows): Function rowsum = 3
┌───┬───┐
│ a │ b │
├───┼───┤
│ 0 │ 3 │
└───┴───┘
Group 4 (1 rows): Function rowsum = 4
┌───┬───┐
│ a │ b │
├───┼───┤
│ 2 │ 2 │
└───┴───┘
Group 5 (1 rows): Function rowsum = 5
┌───┬───┐
│ a │ b │
├───┼───┤
│ 1 │ 4 │
└───┴───┘
Group 6 (1 rows): Function rowsum = 6
┌───┬───┐
│ a │ b │
├───┼───┤
│ 0 │ 6 │
└───┴───┘
Group 7 (2 rows): Function rowsum = 7
┌───┬───┐
│ a │ b │
├───┼───┤
│ 2 │ 5 │
│ 0 │ 7 │
└───┴───┘
Group 8 (1 rows): Function rowsum = 9
┌───┬───┐
│ a │ b │
├───┼───┤
│ 1 │ 8 │
└───┴───┘
Group 9 (1 rows): Function rowsum = 10
┌───┬───┐
│ a │ b │
├───┼───┤
│ 1 │ 9 │
└───┴───┘