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

Multiplication not allowed for bool dtype #19919

Closed
2 tasks done
jesusestevez opened this issue Nov 22, 2024 · 2 comments
Closed
2 tasks done

Multiplication not allowed for bool dtype #19919

jesusestevez opened this issue Nov 22, 2024 · 2 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@jesusestevez
Copy link

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import polars as pl

df = pl.DataFrame(
    {"sets": [["a", "b"], ["a", "b"], ["a", "b"]], 
     "optional_members": [["a", "b"], ["a", "b"], ["a", "c"]],
     "exposure": [[1, 2], [3, 4], [5, 6]]}
)

lookup = df.with_columns(
    pl.col.sets.explode().is_in(pl.col.optional_members.explode())
    .implode()
    .over(pl.int_range(pl.len()))
    .alias("lookup_result")
)


lookup.with_columns(pl.col("lookup_result") * pl.col("exposure"))

Log output

No response

Issue description

Following #8006 , I would expect list multiplication to be allowed for boolean dtypes, behaving as the list division. However, it seems it is not supported. Is there any reason for this behaviour?

Expected behavior

I would expect the multiplication (when one of the columns is bool dtype, to behave as the division:

import polars as pl

df = pl.DataFrame(
    {"sets": [["a", "b"], ["a", "b"], ["a", "b"]], 
     "optional_members": [["a", "b"], ["a", "b"], ["a", "c"]],
     "exposure": [[1, 2], [3, 4], [5, 6]]}
)

lookup = df.with_columns(
    pl.col.sets.explode().is_in(pl.col.optional_members.explode())
    .implode()
    .over(pl.int_range(pl.len()))
    .alias("lookup_result")
)


lookup.with_columns(pl.col("lookup_result") / pl.col("exposure"))

Installed versions

Replace this line with the output of pl.show_versions(). Leave the backticks in place.
@jesusestevez jesusestevez added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Nov 22, 2024
@cmdlineluser
Copy link
Contributor

cmdlineluser commented Nov 22, 2024

It doesn't mention what error you get or the pl.show_versions() output, but this is what I get on 1.14.0

lookup.with_columns(pl.col("lookup_result") * pl.col("exposure"))
# shape: (3, 4)
# ┌────────────┬──────────────────┬───────────┬───────────────┐
# │ sets       ┆ optional_members ┆ exposure  ┆ lookup_result │
# │ ---        ┆ ---              ┆ ---       ┆ ---           │
# │ list[str]  ┆ list[str]        ┆ list[i64] ┆ list[i64]     │
# ╞════════════╪══════════════════╪═══════════╪═══════════════╡
# │ ["a", "b"] ┆ ["a", "b"]       ┆ [1, 2]    ┆ [1, 2]        │
# │ ["a", "b"] ┆ ["a", "b"]       ┆ [3, 4]    ┆ [3, 4]        │
# │ ["a", "b"] ┆ ["a", "c"]       ┆ [5, 6]    ┆ [5, 0]        │
# └────────────┴──────────────────┴───────────┴───────────────┘

@jesusestevez
Copy link
Author

I missed an update. Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

2 participants