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

Add a custom html dataframe rendering view of nested columns #41

Open
dougbrn opened this issue May 2, 2024 · 2 comments · May be fixed by #103
Open

Add a custom html dataframe rendering view of nested columns #41

dougbrn opened this issue May 2, 2024 · 2 comments · May be fixed by #103
Labels
enhancement New feature or request

Comments

@dougbrn
Copy link
Collaborator

dougbrn commented May 2, 2024

We have control over the dataframe output within Pandas: https://pandas.pydata.org/docs/user_guide/style.html

When left unstyled, Pandas tries to print the dataframe directly into the cell values. We should have a custom rendering that changes this to be some simple representative value, like: <NestedFrame>. Optionally we could try to give this some more descriptive metadata, but I worry about the overhead of calculating such information if the user doesn't need it. e.g. <NestedFrame (length=350)>

@dougbrn dougbrn added the enhancement New feature or request label May 2, 2024
@dougbrn
Copy link
Collaborator Author

dougbrn commented May 7, 2024

This code is likely what we're after, it alters the default representation without converting it to a styler object:

def my_style(df:NestedFrame):
    return (df.style.format({"nested": ""}))

def _my_repr_html_(self) -> str | None:
    return self.pipe(my_style)._repr_html_() # <<<< !!! HERE !!! 
        
NestedFrame._repr_html_ = _my_repr_html_

Note that one quirk of this is that my_style needs to know what columns to style manually, so we may need to trigger this in add_nested calls and reassert the styling.

@hombit
Copy link
Collaborator

hombit commented Jun 3, 2024

Connected to #64

@dougbrn dougbrn linked a pull request Jun 5, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants