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

WIP: Custom HTML Rendering for Nested Columns #103

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/nested_pandas/nestedframe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
nest_cols.append(column)
return nest_cols

def _repr_html_(self) -> str | None:
"""Override html representation"""

def my_style(df: NestedFrame, columns):

Check warning on line 58 in src/nested_pandas/nestedframe/core.py

View check run for this annotation

Codecov / codecov/patch

src/nested_pandas/nestedframe/core.py#L58

Added line #L58 was not covered by tests
"""Style generator for nested columns"""
style = {column: f"&ltcolumns={df[column].nest.fields}&gt" for column in columns}
return df.style.format(style)

Check warning on line 61 in src/nested_pandas/nestedframe/core.py

View check run for this annotation

Codecov / codecov/patch

src/nested_pandas/nestedframe/core.py#L60-L61

Added lines #L60 - L61 were not covered by tests

max_rows = pd.get_option("display.max_rows")
repr = super().pipe(my_style, self.nested_columns).to_html(max_rows=max_rows)
return repr

Check warning on line 65 in src/nested_pandas/nestedframe/core.py

View check run for this annotation

Codecov / codecov/patch

src/nested_pandas/nestedframe/core.py#L63-L65

Added lines #L63 - L65 were not covered by tests

def _is_known_hierarchical_column(self, colname) -> bool:
"""Determine whether a string is a known hierarchical column name"""
if "." in colname:
Expand Down