Skip to content

feat(polars): add ArrayUnion operation #10330

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

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

IndexSeek
Copy link
Member

Description of changes

Implements ArrayUnion with pl.Series.list.set_union.

Reasoning for test marker adjustment

I was also running into the NaN issue that occurs with DataFusion. Here's some code I was using to test this.

In [1]: import polars as pl
   ...: from ibis.interactive import *

In [2]: left, right = [[3, 2], [], []], [[1, 3], [None], [5]]

In [3]: df = pl.DataFrame([left, right], schema=["left", "right"])

In [4]: df
Out[4]: 
shape: (3, 2)
┌───────────┬───────────┐
│ left      ┆ right     │
│ ---       ┆ ---       │
│ list[i64] ┆ list[i64] │
╞═══════════╪═══════════╡
│ [3, 2]    ┆ [1, 3]    │
│ []        ┆ [null]    │
│ []        ┆ [5]       │
└───────────┴───────────┘

In [5]: duck_con = ibis.connect("duckdb://")
   ...: polars_con = ibis.connect("polars://")

In [6]: for con in (duck_con, polars_con):
   ...:     t = con.create_table("t", df, overwrite=True)
   ...:     expr = t.left.union(t.right)
   ...:     print(t.get_backend().name)
   ...:     print(con.execute(expr))
   ...: 
duckdb
0    [1, 2, 3]
1       [None]
2          [5]
Name: ArrayUnion(left, right), dtype: object
polars
0    [3.0, 2.0, 1.0]
1              [nan]
2              [5.0]
Name: ArrayUnion(left, right), dtype: object

The following is mentioned in the docs at https://docs.pola.rs/user-guide/expressions/missing-data/#notanumber-or-nan-values:

In pandas by default a NaN value in an integer column causes the column to be cast to float. This does not happen in Polars - instead an exception is raised.

I wonder if this happens when going to pandas by way of execute.

@github-actions github-actions bot added tests Issues or PRs related to tests polars The polars backend labels Oct 18, 2024
@cpcloud cpcloud added this to the 10.0 milestone Oct 18, 2024
@cpcloud cpcloud merged commit 4d5e847 into ibis-project:main Oct 18, 2024
77 checks passed
@IndexSeek IndexSeek deleted the polars-array-union branch October 30, 2024 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
polars The polars backend tests Issues or PRs related to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants