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

Refactor: do not route vals_ methods through GT object #266

Open
machow opened this issue Apr 4, 2024 · 1 comment
Open

Refactor: do not route vals_ methods through GT object #266

machow opened this issue Apr 4, 2024 · 1 comment

Comments

@machow
Copy link
Collaborator

machow commented Apr 4, 2024

Currently, functions like vals.fmt_number() work as follows:

  • The input list or value is converted to a pandas DataFrame
  • The DataFrame is wrapped in GT
  • The corresponding fmt_ method is run
  • The formatted values are extracted as a list

This is problematic for two reasons:

  • It creates a hard dependency on pandas
  • It feels a bit circuitous to wrap in GT, run, then take out

Removing use of GT

Fortunately, it seems that GT.fmt_* methods don't make much use of the GT object. Uses seem to be largely:

  • Getting a default locale setting
  • Passing in the DataFrame to dispatch on for is_na() checks
  • At the very end, attaching to GT._formatters, and returning a new GT object

It seems like we could pretty easily run vals.fmt_* funcs straight over formatter logic. This would let us remove the pandas dependency.

Alternatively..

An alternative would be for us to support GT(SomeInBuiltFrame). GT's core logic does not require a very beefed up DataFrame implementation. We could get away with a class that's essentially a dictionary of same-length lists. This might actually be easier, since we wouldn't need to refactor the formatter code.

@machow
Copy link
Collaborator Author

machow commented Apr 4, 2024

Alternatively alternatively...

We could support inputting a pandas series or polars series as the input values. We have the machinery to detect these, and at that point do pandas/polars specific things w/o creating any dependencies.

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

No branches or pull requests

1 participant