# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_jupyterutils.ipynb.

# %% auto 0
__all__ = ['display_df_with_color']

# %% ../nbs/02_jupyterutils.ipynb 3
from IPython.display import display
import pandas as pd
import numpy as np
import polars as pl
import seaborn as sns

# %% ../nbs/02_jupyterutils.ipynb 5
def display_df_with_color(df):
    """
    Display a pandas or polars DataFrame with color-coded background in Jupyter Notebook.
    Applies color coding to all numeric columns.
    """
    # Check if the DataFrame is a Polars DataFrame and convert it to Pandas if necessary
    if isinstance(df, pl.DataFrame):
        df = df.to_pandas()

    # Create a color map
    cmap = sns.light_palette("blue", as_cmap=True)

    # Select numeric columns for gradient and formatting
    numeric_cols = df.select_dtypes(include=np.number).columns

    # Apply the color map and number formatting to numeric columns
    styled_df = df.style.background_gradient(cmap=cmap, subset=pd.IndexSlice[:, numeric_cols]).format("{:.3f}", subset=numeric_cols)

    # Display the DataFrame
    display(styled_df)
