Config#

Config options#

Config.set_ascii_tables([active])

Use ASCII characters to display table outlines.

Config.set_auto_structify([active])

Allow multi-output expressions to be automatically turned into Structs.

Config.set_decimal_separator([separator])

Set the decimal separator character.

Config.set_float_precision([precision])

Control the number of decimal places displayed for floating point values.

Config.set_fmt_float([fmt])

Control how floating point values are displayed.

Config.set_fmt_str_lengths(n)

Set the number of characters used to display string values.

Config.set_fmt_table_cell_list_len(n)

Set the number of elements to display for List values.

Config.set_streaming_chunk_size(size)

Overwrite chunk size used in streaming engine.

Config.set_tbl_cell_alignment(format)

Set table cell alignment.

Config.set_tbl_cell_numeric_alignment(format)

Set table cell alignment for numeric columns.

Config.set_tbl_cols(n)

Set the number of columns that are visible when displaying tables.

Config.set_tbl_column_data_type_inline([active])

Moves the data type inline with the column name (to the right, in parentheses).

Config.set_tbl_dataframe_shape_below([active])

Print the DataFrame shape information below the data when displaying tables.

Config.set_tbl_formatting([format, ...])

Set table formatting style.

Config.set_tbl_hide_column_data_types([active])

Hide table column data types (i64, f64, str etc.).

Config.set_tbl_hide_column_names([active])

Hide table column names.

Config.set_tbl_hide_dataframe_shape([active])

Hide the DataFrame shape information when displaying tables.

Config.set_tbl_hide_dtype_separator([active])

Hide the '---' separator between the column names and column types.

Config.set_tbl_rows(n)

Set the max number of rows used to draw the table (both Dataframe and Series).

Config.set_tbl_width_chars(width)

Set the maximum width of a table in characters.

Config.set_thousands_separator([separator])

Set the thousands grouping separator character.

Config.set_trim_decimal_zeros([active])

Strip trailing zeros from Decimal data type values.

Config.set_verbose([active])

Enable additional verbose/debug logging.

Config load, save, state#

Config.load(cfg)

Load (and set) previously saved Config options from a JSON string.

Config.load_from_file(file)

Load (and set) previously saved Config options from file.

Config.save(*[, if_set])

Save the current set of Config options as a JSON string.

Config.save_to_file(file)

Save the current set of Config options as a JSON file.

Config.state(*[, if_set, env_only])

Show the current state of all Config variables as a dict.

Config.restore_defaults()

Reset all polars Config settings to their default state.

While it is easy to restore all configuration options to their default value using restore_defaults, it can also be useful to reset individual options. This can be done by setting the related value to None, eg:

pl.Config.set_tbl_rows(None)

Use as a context manager#

Note that Config supports setting context-scoped options. These options are valid only during scope lifetime, and are reset to their initial values (whatever they were before entering the new context) on scope exit.

You can take advantage of this by initialising a Config instance and then explicitly calling one or more of the available “set_” methods on it…

with pl.Config() as cfg:
    cfg.set_verbose(True)
    do_various_things()

# on scope exit any modified settings are restored to their previous state

…or, often cleaner, by setting the options in the Config init directly (optionally omitting the “set_” prefix for brevity):

with pl.Config(verbose=True):
    do_various_things()

Use as a decorator#

In the same vein, you can also use Config as a function decorator to temporarily set options for the duration of the function call:

@pl.Config(set_ascii_tables=True)
def write_ascii_frame_to_stdout(df: pl.DataFrame) -> None:
    sys.stdout.write(str(df))