lifelines icon indicating copy to clipboard operation
lifelines copied to clipboard

Add support for polars

Open pavelzw opened this issue 6 months ago • 6 comments

Currently, lifelines only supports pandas for its operations. It would be great if there was polars support. It might be interesting to look into narwhals which allows projects to support multiple backends, i.e. pandas and polars.

pavelzw avatar Jun 13 '25 13:06 pavelzw

@pavelzw I'm working on implementing aj estimates (nonparametric estimation as km / cif) supported by polars. It might be helpful to you?

uriahf avatar Jul 07 '25 08:07 uriahf

We are using KaplerMeierFilter and CoxPHFitter from lifelines. If those had the option of outputting polars instead of pandas, that would be great

pavelzw avatar Jul 07 '25 08:07 pavelzw

I can help you out with KM, but Cox regression is a semi-parametric method and that might be trickier to implement.

uriahf avatar Jul 07 '25 11:07 uriahf

I would be happy to contribute to this by modifying the CTV fitter. The main reason being the run time to fit the model is far too slow due to pandas and not polars being used.

I'm not familiar with the source, but I believe if the library moves some functions to polars this should be done for all functions. Although this would require polars for all users. Any maintainers got thoughts on this?

I happy to submit a PR but im not going to waste my time if there are other considerations already being made, polars is not the only option for large dataframe processing, duckdb would be even faster.

jannik-el avatar Aug 08 '25 08:08 jannik-el

i think to be able to support both polars and pandas, it would be nice to look a bit into narwhals. the syntax is very modern polars-like but under the hood can get translated to pandas if people use pandas.

pavelzw avatar Aug 08 '25 08:08 pavelzw

I agree I think this is a good idea, this will however require a major code refactoring and I'm not doing that unless I can see any interest from one of the main maintainers. Thoughts @CamDavidsonPilon ?

jannik-el avatar Aug 08 '25 09:08 jannik-el