Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support arthimetic on Python objects #14568

Closed
staadecker opened this issue Feb 17, 2024 · 1 comment
Closed

Support arthimetic on Python objects #14568

staadecker opened this issue Feb 17, 2024 · 1 comment
Labels
enhancement New feature or an improvement of an existing feature

Comments

@staadecker
Copy link

Description

A common behavior for Python objects is to override the add or mul functions to allow multiplying or adding objects together. For example in this library built on-top of Pandas, dataframe columns storing custom Python objects are multiplied together to and then aggregated with .sum() to create optimization models.

Having similar support for multiplying and adding custom Python objects in dataframes would be incredibly helpful.

@staadecker staadecker added the enhancement New feature or an improvement of an existing feature label Feb 17, 2024
@stinodego
Copy link
Member

We will not support this natively, but you can already do this if you want using the various map functions together with a UDF:

import polars as pl

df = pl.Series("a", [1, 2, 3], dtype=pl.Object).to_frame()

result = df.select(pl.col("a").map_batches(lambda x: sum(x), agg_list=True))
print(result)
shape: (1, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 6   │
└─────┘

@stinodego stinodego closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants