posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.9k stars 72 forks source link

Issue 283 nano plot scaling #404

Open minimav opened 4 months ago

minimav commented 4 months ago

Summary

This PR fixes a bug whereby values from unselected rows affect the scaling in nanoplots. In addition to the single values case given in #283, a simple example of the bug in the context of multiple values per row is below (when autoscale is used):

multiple_vals_df = pd.DataFrame(
    {
        "i": list(range(1, 3)),
        "lines_small": ["12.44 6.34", "5.2 -8.2 10"],
        "lines_large": ["12.44, 6.34", "5.2 -8.2 100"],
    }
)
(
    GT(multiple_vals_df, rowname_col="i")
    .fmt_nanoplot(columns="lines_small", rows=[0], plot_type="line", autoscale=True)
    .fmt_nanoplot(columns="lines_large", rows=[0], plot_type="line", autoscale=True)
)
Screenshot 2024-07-18 at 20 49 20

Single values example post-fix:

Screenshot 2024-07-18 at 19 53 06

Multiple values example post-fix:

Screenshot 2024-07-18 at 19 53 29

I have added a couple of unit tests based on existing ones, let me know if they work. Thanks for your work on this library, I have been using it at work and really enjoying it 🙂

Related GitHub Issues and PRs

Checklist

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 86.64%. Comparing base (f8e30ea) to head (f1df81e).

Files Patch % Lines
great_tables/_formats.py 83.33% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #404 +/- ## ========================================== + Coverage 86.40% 86.64% +0.24% ========================================== Files 42 42 Lines 4700 4704 +4 ========================================== + Hits 4061 4076 +15 + Misses 639 628 -11 ```

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