Skip to content

BUG: pandas.Styler.__repr__ and pandas.Styler.__str__ cause nbconvert failure to display data #55908

Open
@yasirroni

Description

@yasirroni

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

from IPython.display import display, HTML

import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.random((2,3)))
display(df)  # this will send print(df) to  "text/plain": [...]

df_style = df.style.set_caption("data")
display(df_style)  # this will send print(df_style) to  "text/plain": [...]

Issue Description

Refer to my issue in nbconvert

Basically, nbconvert use what is in "text/plain": [...]. Displaying something using display seems to send object.__repr__ or object.__str__ there. Sadly, pd.style.Styler return <pandas.io.formats.style.Styler at 0x...> on print. Please at least change pd.style.Styler.__repr__ and pd.style.Styler.__str__ into a human readable meaningful text, that is, at least, sending pd.style.Styler.data.__repr__ and pd.style.Styler.data.__str__.

Expected Behavior

pd.style.Styler.__repr__ and pd.style.Styler.__str__ has a human readable and meaningful text, that is, at least, like pd.style.Styler.data.__repr__ and pd.style.Styler.data.__str__.

Installed Versions

I use python 3.8, pd.show_versions throws error.

Here is pandas version: '2.0.3'

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementOutput-Formatting__repr__ of pandas objects, to_stringStylerconditional formatting using DataFrame.style

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions