Skip to content

Add PrettyTables rendering for GDTable #48

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

harsharora21
Copy link
Contributor

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 │
├───────┼───────┤
│     00 │
│     03 │
│     06 │
│     07 │
│     22 │
│     25 │
│     11 │
│     14 │
│     18 │
│     19 │
└───────┴───────┘

@krynju
Copy link
Member

krynju commented Sep 1, 2023

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
Copy link

codecov-commenter commented Sep 4, 2023

Codecov Report

Patch coverage has no change and project coverage change: -3.01% ⚠️

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

❗ 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
@@            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 Coverage Δ
src/table/gdtable.jl 51.72% <0.00%> (-24.55%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@harsharora21
Copy link
Contributor Author

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 │
├───┼───┤
│ 00 │
│ 03 │
│ 06 │
│ 07 │
└───┴───┘

Last Group (2 rows): a = 2
┌───┬───┐
│ a │ b │
├───┼───┤
│ 22 │
│ 25 │
└───┴───┘


julia> print(gdt)
GDTable with 3 partitions and 3 keys
Tabletype: NamedTuple
Grouped by: [:a]
Group 1 (4 rows): a = 0
┌───┬───┐
│ a │ b │
├───┼───┤
│ 00 │
│ 03 │
│ 06 │
│ 07 │
└───┴───┘
Group 2 (4 rows): a = 1
┌───┬───┐
│ a │ b │
├───┼───┤
│ 11 │
│ 14 │
│ 18 │
│ 19 │
└───┴───┘
Group 3 (2 rows): a = 2
┌───┬───┐
│ a │ b │
├───┼───┤
│ 22 │
│ 25 │
└───┴───┘

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 │
├───┼───┤
│ 00 │
└───┴───┘

Last Group (1 rows): Function rowsum = 10
┌───┬───┐
│ a │ b │
├───┼───┤
│ 19 │
└───┴───┘


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

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

Successfully merging this pull request may close these issues.

3 participants