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

Fix nanoplots listcols #330

Merged
merged 3 commits into from
May 8, 2024
Merged

Fix nanoplots listcols #330

merged 3 commits into from
May 8, 2024

Conversation

machow
Copy link
Collaborator

@machow machow commented May 7, 2024

This PR ensures Great Tables can render a polars DataFrame that has a pl.List column. Previously, it would error, and the error was early enough that formatters couldn't work with this data.

(Note that most formatters are not designed to work with list columns. We may need to support this down the road, or add helpful messaging when erroring in these cases).

(Note also that this might fail for complex list schemas, eg. nested lists like pl.List(pl.List(int)) rather than pl.List(int). But this case also fails in the current code).

Here's a hokey example displaying a table with list columns:

from great_tables import GT
import polars as pl

GT(pl.DataFrame({"x": [[1, 2], [3]], "y": [[.9], [1.1]]}))
image

And with a tasty nanoplot

GT(pl.DataFrame({"x": [[1, 2], [3]], "y": [[.9], [1.1]]})).fmt_nanoplot("x")
image

@machow machow requested a review from rich-iannone May 7, 2024 21:45
@machow machow marked this pull request as ready for review May 7, 2024 21:45
'''
<tbody class="gt_table_body">
<tr>
<td class="gt_row gt_center"><div><svg role="img" viewBox="0 0 200 130" style="height: 2em; margin-left: auto; margin-right: auto; font-size: inherit; overflow: visible; vertical-align: middle; position:relative;"><defs><pattern id="area_pattern" width="8" height="8" patternUnits="userSpaceOnUse"><path class="pattern-line" d="M 0,8 l 8,-8 M -1,1 l 4,-4 M 6,10 l 4,-4" stroke="#FF0000" stroke-width="1.5" stroke-linecap="round" shape-rendering="geometricPrecision"></path></pattern></defs><style> text { font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace; stroke-width: 0.15em; paint-order: stroke; stroke-linejoin: round; cursor: default; } .vert-line:hover rect { fill: #911EB4; fill-opacity: 40%; stroke: #FFFFFF60; color: red; } .vert-line:hover text { stroke: white; fill: #212427; } .horizontal-line:hover text {stroke: white; fill: #212427; } .ref-line:hover rect { stroke: #FFFFFF60; } .ref-line:hover line { stroke: #FF0000; } .ref-line:hover text { stroke: white; fill: #212427; } .y-axis-line:hover rect { fill: #EDEDED; fill-opacity: 60%; stroke: #FFFFFF60; color: red; } .y-axis-line:hover text { stroke: white; stroke-width: 0.20em; fill: #1A1C1F; } </style><path class="area-closed" d="M 50.0,115.0 150.0,15.0 150.0,125 50.0,125 Z" stroke="transparent" stroke-width="2" fill="url(#area_pattern)" fill-opacity="0.7"></path><path d="M 50.0,115.0 C 75.0,115.0 125.0,15.0 150.0,15.0" stroke="#4682B4" stroke-width="8" fill="none"></path><circle cx="50.0" cy="115.0" r="10" stroke="#FFFFFF" stroke-width="4" fill="#FF0000"></circle><circle cx="150.0" cy="15.0" r="10" stroke="#FFFFFF" stroke-width="4" fill="#FF0000"></circle><g class="y-axis-line"><rect x="0" y="0" width="65" height="130" stroke="transparent" stroke-width="0" fill="transparent"></rect><text x="0" y="19.0" fill="transparent" stroke="transparent" font-size="25">2</text><text x="0" y="126.0" fill="transparent" stroke="transparent" font-size="25">1</text></g><g class="vert-line"><rect x="40.0" y="0" width="20" height="130" stroke="transparent" stroke-width="12" fill="transparent"></rect><text x="60.0" y="20" fill="transparent" stroke="transparent" font-size="30px">1</text></g><g class="vert-line"><rect x="140.0" y="0" width="20" height="130" stroke="transparent" stroke-width="12" fill="transparent"></rect><text x="160.0" y="20" fill="transparent" stroke="transparent" font-size="30px">2</text></g></svg></div></td>
Copy link
Collaborator Author

@machow machow May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. I wonder if there's a better way to test this simple case, but it might be a resolve down the road situation 😭

Copy link
Member

@rich-iannone rich-iannone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@machow machow merged commit f5977b3 into main May 8, 2024
9 checks passed
@rich-iannone rich-iannone deleted the fix-nanoplots-listcols branch May 8, 2024 20:48
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.

None yet

2 participants