great-tables icon indicating copy to clipboard operation
great-tables copied to clipboard

.fmt_nanoplot inconsistently requires Pandas

Open knutmerket opened this issue 2 months ago • 0 comments

Prework

Description

When passed a polars column of list type (Int64 in example below - but same result with other int/float types as well as when using a struct with lists) great_tables inconsistently complains about Pandas missing.

.fmt_nanoplot

Reproducible example

On a fresh virtual environment, with Polars and great-tables installed (but not Pandas), this example works:

random_numbers_df = pl.DataFrame(
    {
        "example": ["Row " + str(x) for x in range(1, 3)],
        "numbers": [
            [20, 23, 6, 7, 37, 23, 21, 4, 7, 16],
            [2, 0, 15, 7, 8, 10, 1, 24, 17, 13, 6],
        ],
    },
)

GT(random_numbers_df).fmt_nanoplot(columns="numbers")

... but this (different values in numbers lists, and different length of lists) does not:

random_numbers_df = pl.DataFrame(
    {
        "example": ["Row " + str(x) for x in range(1, 3)],
        "numbers": [
            [558, 480, 688, 610, 761, 614],
            [486, 472, 428, 496, 587, 530],
        ],
    },
)

GT(random_numbers_df).fmt_nanoplot(columns="numbers")

The second example gives me the following error:

ModuleNotFoundError: No module named 'pandas' [...] ImportError: Passing a plain list of values currently requires the library pandas. You can avoid this error by passing a polars Series

Inspecting the schema of the two versions of the dataframe with random_numbers_df.schema yields identical results:

Schema([('example', String), ('numbers', List(Int64))])

Expected result

Either both examples should succeed or fail without Pandas installed. I hope the expected result is that this should work fine without Pandas installed.

Development environment

  • Operating System: Mac
  • Python: 3.13
  • great_tables Version: 0.18.0
  • polars Version: 1.33.1

Additional context

Add any other context about the problem here.

knutmerket avatar Sep 17 '25 12:09 knutmerket