posit-dev / great-tables

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

fix: `fmt` cannot accept multiple `fns` #327

Open jrycw opened 2 months ago

jrycw commented 2 months ago

Currently , the following code will raise AttributeError: 'list' object has no attribute 'default'.

from great_tables import GT, exibble

(
    GT(exibble[["fctr"]])
    .fmt([lambda x: x], columns="fctr")
)

The main issue appears to be that fmt did not handle fns properly when it is a list. As a result, the callables are not wrapped in FormatFns. Additionally, Body.render_formats needs to be refactored to accommodate this change by retrieving the result of _set_cell for each call. Given the critical role of fmt within this project, while the proposed PR may not be flawless, it serves as a reference for our refactoring efforts. With some snapshot tests failing, I would greatly appreciate the team's assistance in reviewing the PR to ensure the failed tests are acceptable.

jrycw commented 1 month ago

@machow , thank you so much for explaining the details to me. I believe making a small modification to the docs will make it easier for people who haven't used {gt} before (like me). Since I'll be out of town for a few days, would you mind taking over the PR to either close it or modify the docs?

machow commented 1 month ago

I believe making a small modification to the docs will make it easier for people who haven't used {gt} before (like me)

That makes a ton of sense --- I can make sure to change the docstring Monday. I'll look back through to see if there are pieces to keep from the PR (since it seemed like there were some other improvements in here :)

jrycw commented 1 month ago

@machow, thanks a lot.