Skip to content

[ENH] Support polars via Python dataframe interchange protocol  #474

@lorentzenchr

Description

@lorentzenchr

Is your feature request related to a problem? Please describe.
I would like to preprocess my data in other data containers than pandas, e.g. pyarrow and polars, and then apply Triangle to it.

Is your feature request at odds with the scope of the package?

import chainladder as cl
import pandas as pd
import polars as pl


raa_df = pd.read_csv(
    "https://raw.githubusercontent.com/casact/chainladder-python/master/chainladder/utils/data/raa.csv"
)

# This works just fine
raa = cl.Triangle(
    raa_df,
    origin="origin",
    development="development",
    columns="values",
    cumulative=True,
)

# This gives an error
raa_pl = pl.read_csv(
    "https://raw.githubusercontent.com/casact/chainladder-python/master/chainladder/utils/data/raa.csv"
)

cl.Triangle(
    raa_pl,
    origin="origin",
    development="development",
    columns="values",
    cumulative=True,
)

results in

AttributeError: 'DataFrame' object has no attribute 'iloc'

Describe the solution you'd like
Supporting data via the Python dataframe interchange protocol might be an optimal approach.

Describe alternatives you've considered
One could also consider polars specific code path. But this might result in more maintenance burden: Where to stop? Add pyarrow, too?

Additional context
A similar feature request is scikit-learn/scikit-learn#25896 which is currently worked on.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions