Skip to content

dataframe

Utilities for Polars frames: reading files, hashing, input conversion.

Functions:

uncompressed_extension(file_name)

The extension of a file name, ignoring a compression suffix.

read_polars(file_name)

Open a data file lazily, choosing the reader from the extension.

CSV (and .tsv, .txt, .data), Parquet, Arrow IPC / Feather, newline-delimited JSON and JSON are supported. Only JSON is read eagerly. Files with another extension are read as CSV.

infer_objects(df)

Give Object columns a real dtype when their values allow it.

Polars builds Object columns from, e.g., numpy object arrays that mix strings and None. Their values are re-read so that such a column becomes a String column (as pandas.DataFrame.infer_objects would do); columns of arbitrary Python objects stay Object.

to_lazyframe(df)

Accept a Polars frame or anything Polars can build a frame from.

pyarrow tables and record batches, objects implementing the Arrow PyCapsule stream interface (DuckDB relations, ...) and dicts of columns are converted without going through pandas.

hash_dataframe(df)

Hash a frame's schema and contents (computed lazily).

Polars' row hashes are not stable across Polars versions, so neither is this hash.

slugify(value, allow_unicode=False)

Taken from https://github.com/django/django/blob/master/django/utils/text.py Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren't alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and trailing whitespace, dashes, and underscores.