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

sample() inside agg() seems to cause incorrect Schema for LazyFrame #18683

Closed
2 tasks done
cmdlineluser opened this issue Sep 11, 2024 · 1 comment
Closed
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@cmdlineluser
Copy link
Contributor

cmdlineluser commented Sep 11, 2024

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.LazyFrame({"id": [1, 2], "val": [3, 4]})

(df.group_by("id")
   .agg(pl.col.val.sample(pl.len()))
   .with_columns(
       same = pl.col.val.list.set_intersection(pl.col.val)
   )
   .collect()
)
# InvalidOperationError: expected List type, got: i64

Log output

No response

Issue description

Should this not be List(Int64)?

(df.group_by("id")
   .agg(pl.col.val.sample(pl.len()))
   .collect_schema()["val"]
)
# Int64

An early collect shows the working query.

(df.group_by("id")
   .agg(pl.col.val.sample(pl.len()))
   .collect()
   .with_columns(
       same = pl.col.val.list.set_intersection(pl.col.val)
   )
)

# shape: (2, 3)
# ┌─────┬───────────┬───────────┐
# │ id  ┆ val       ┆ same      │
# │ --- ┆ ---       ┆ ---       │
# │ i64 ┆ list[i64] ┆ list[i64] │
# ╞═════╪═══════════╪═══════════╡
# │ 1   ┆ [3]       ┆ [3]       │
# │ 2   ┆ [4]       ┆ [4]       │
# └─────┴───────────┴───────────┘

But other .list functions seem to work OK, so not sure if it something specific to .list.set_* ones.

(df.group_by("id")
   .agg(pl.col.val.sample(pl.len()))
   .with_columns(
       len = pl.col.val.list.len()
   )
   .collect()
)

# shape: (2, 3)
# ┌─────┬───────────┬─────┐
# │ id  ┆ val       ┆ len │
# │ --- ┆ ---       ┆ --- │
# │ i64 ┆ list[i64] ┆ u32 │
# ╞═════╪═══════════╪═════╡
# │ 1   ┆ [3]       ┆ 1   │
# │ 2   ┆ [4]       ┆ 1   │
# └─────┴───────────┴─────┘

Expected behavior

No exception.

Installed versions

--------Version info---------
Polars:               1.6.0
Index type:           UInt32
Platform:             macOS-13.6.1-arm64-arm-64bit
Python:               3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         <not installed>
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.1
pyarrow:              15.0.2
pydantic:             <not installed>
pyiceberg:            <not installed>
sqlalchemy:           <not installed>
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@cmdlineluser cmdlineluser added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Sep 11, 2024
@cmdlineluser
Copy link
Contributor Author

Fixed by #19016

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

1 participant