Polars / Python Limits Number of Printed Table Output Rows
Asked Answered
E

2

5

Does anyone know why polars (or maybe my pycharm setup or python debugger) limits the number of rows in the output? This drives me nuts.

Here is the polars code i am running but I do suspect its not polars specific as there isnt much out there on google (and chatgpt said its info is too old haha).

import polars as pl

df = pl.scan_parquet('/path/to/file.parquet')
result_df =(
        df
        .filter(pl.col("condition_category") == 'unknown')
        .groupby("type")
        .agg(
            [
                pl.col("type").count().alias("counts"),
            ]
        )
    ).collect()
print(result_df)

polars printout of query result

Embrey answered 17/4, 2023 at 13:46 Comment(2)
It's a string column, so hopefully set_fmt_str_lengths works?Accretion
Tried and didnt work: with pl.Config() as cfg: cfg.set_fmt_str_lengths(200000) print(result_df)Embrey
E
7

Looks like the following will work. Thanks to @wayoshi for sharing this. I will say that the defaults are way too conservative!

with pl.Config(tbl_rows=1000):
    print(result_df)

or throw this at the top of your script if you prefer to not manage contexts.

import polars as pl

# Configure Polars 
cfg = pl.Config()
cfg.set_tbl_rows(2000)
Embrey answered 17/4, 2023 at 13:57 Comment(2)
Oh I misread the question as string truncation and not row, my bad.Accretion
@Accretion Me too. I edited the question to be more explicit/direct.Paramorphism
S
1

You can just put this at the top.

import polars as pl
pl.Config(tbl_rows=50)

You can do 50 rows and 10 columns like this:-

import polars as pl
pl.Config(tbl_rows=50, tbl_cols=10)
Selfexistent answered 26/7 at 21:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.