Skip to content

Extend dataset stats: Polars datasets #2730

Description

@ravi-kumar-pilla

Parent: #1511

Description

Polars is used in a lot of newer Kedro projects but dataset stats only look for pd.DataFrame right now. This ticket adds support for kedro-datasets Polars connectors:

  • polars.CSVDataset
  • polars.EagerPolarsDataset
  • polars.LazyPolarsDataset

Context

Stats are collected in DatasetStatsHook.create_dataset_stats() during kedro run and written to .viz/stats.json. The metadata panel reads rows, columns, and file size from there.

Eager Polars frames are straightforward. Lazy frames are trickier because row count usually means running a query unless we skip it.

Possible implementation

Lazy import polars inside create_dataset_stats(), same pattern as pandas.

For polars.DataFrame:

  • rows via height or len(data)
  • columns via width or len(data.columns)
  • file size from existing get_file_size() when the catalog entry has a filepath

For polars.LazyFrame:

  • columns from schema without collecting the whole frame
  • rows either via something like select(pl.len()).collect() or leave rows out for lazy loads and say so in docs

Keep the same JSON keys as pandas so the UI does not need a redesign.

Tests with small Polars fixtures in test_hooks.py. Mark optional in CI if polars is not always installed.

Possible alternatives

Convert to pandas and reuse the existing branch. Easy but bad for large tables.

LazyFrame v1 could be columns and file size only, rows later.

Skip quietly with a log message if polars is not installed.

Deliverables

  • Hook handles polars.DataFrame and polars.LazyFrame
  • Stats in .viz/stats.json and metadata panel for Polars catalog entries
  • Clear note on what happens for LazyFrame row counts
  • Unit tests

Checklist

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status
    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions