itables icon indicating copy to clipboard operation
itables copied to clipboard

used pandas styles with show raise TypeError

Open sravel opened this issue 2 years ago • 1 comments

Hello,

I have error when I used both show and pandas styles, I use this code:

# create a sample DataFrame
df = pd.read_csv('all_stats.csv', index_col=False)
df.sort_values(by=df.columns[0], axis=0, inplace=True)
S = df.style.format(precision=2)
S.background_gradient(axis=0, cmap="YlOrRd")
show(S, dom="lfrt", paging=False, classes="compact cell-border", scrollCollapse=True, scrollX=True)
File ~/.local/lib/python3.9/site-packages/itables/downsample.py:20, in downsample(df, max_rows, max_columns, max_bytes)
     18 def downsample(df, max_rows=0, max_columns=0, max_bytes=0):
     19     """Return a subset of the dataframe that fits the limits"""
---> 20     org_rows, org_columns, org_bytes = len(df), len(df.columns), nbytes(df)
     21     df = _downsample(
     22         df, max_rows=max_rows, max_columns=max_columns, max_bytes=max_bytes
     23     )
     25     if len(df) < org_rows or len(df.columns) < org_columns:

TypeError: object of type 'Styler' has no len()

sravel avatar Nov 30 '23 14:11 sravel

Hi, I am afraid I cannot reproduce the issue. Can you share the csv file? Also, what version of itables are you using?

from itables import init_notebook_mode, show
from itables.sample_dfs import generate_random_df
import pandas as pd
init_notebook_mode(True)

# create a sample DataFrame
df = generate_random_df(10,20)
df.sort_values(by=df.columns[0], axis=0, inplace=True)
S = df.style.format(precision=2)
S.background_gradient(axis=0, cmap="YlOrRd")
show(S, dom="lfrt", paging=False, classes="compact cell-border", scrollCollapse=True, scrollX=True)

image

mwouts avatar Dec 02 '23 10:12 mwouts

Closing as I cannot reproduce the issue. Feel free to open another one with a MRE if the problem persists.

mwouts avatar Feb 10 '24 23:02 mwouts