From 098a0f2d743a7ec3a872e8c8dfe60629f544d9a9 Mon Sep 17 00:00:00 2001 From: Doug Branton Date: Wed, 5 Jun 2024 09:59:08 -0700 Subject: [PATCH] WIP: modified repr with some issues --- src/nested_pandas/nestedframe/core.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/nested_pandas/nestedframe/core.py b/src/nested_pandas/nestedframe/core.py index 6142238..dd8d2f5 100644 --- a/src/nested_pandas/nestedframe/core.py +++ b/src/nested_pandas/nestedframe/core.py @@ -52,6 +52,18 @@ def nested_columns(self) -> list: nest_cols.append(column) return nest_cols + def _repr_html_(self) -> str | None: + """Override html representation""" + + def my_style(df: NestedFrame, columns): + """Style generator for nested columns""" + style = {column: f"<columns={df[column].nest.fields}>" for column in columns} + return df.style.format(style) + + max_rows = pd.get_option("display.max_rows") + repr = super().pipe(my_style, self.nested_columns).to_html(max_rows=max_rows) + return repr + def _is_known_hierarchical_column(self, colname) -> bool: """Determine whether a string is a known hierarchical column name""" if "." in colname: