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

group_by with map_elements result incorrectly gets wrapped in a list for lazyframes #17085

Open
2 tasks done
heshamdar opened this issue Jun 20, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@heshamdar
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
import os
os.environ['POLARS_VERBOSE'] = '1'


def simple_func(x):
    return 1


df = pl.DataFrame({"a": [1, 2, 3, 4, 5]})
out = df.group_by(pl.lit(None)).agg(pl.col("a").map_elements(
        lambda x: simple_func(x), return_dtype=pl.Int64)
    )
print(out.collect_schema())

df = df.lazy()
out = df.group_by(pl.lit(None)).agg(pl.col("a").map_elements(
        lambda x: simple_func(x), return_dtype=pl.Int64)
    )
print(out.collect_schema())

Log output

Schema([('literal', Null), ('a', Int64)])
Schema([('literal', Null), ('a', List(Int64))])
keys/aggregates are not partitionable: running default HASH AGGREGATION

Issue description

When running a group_by aggregation with map_elements in lazy mode, even if the return datatype is specified it will return a schema with that datatype wrapped in a list. This does not happen when running in eager mode.

Expected behavior

The return datatype specified by the user should be honoured, e.g. in the example above, the function is set to return just a single value, and not assume that a list of values is being returned.

Installed versions

--------Version info---------
Polars:               1.0.0-beta.1
Index type:           UInt32
Platform:             macOS-14.2.1-arm64-arm-64bit
Python:               3.10.4 (main, May 28 2022, 12:23:44) [Clang 13.1.6 (clang-1316.0.21.2.5)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          3.0.0
connectorx:           <not installed>
deltalake:            0.15.3
fastexcel:            0.9.1
fsspec:               2024.3.1
gevent:               <not installed>
great_tables:         0.6.0
hvplot:               <not installed>
matplotlib:           3.8.3
nest_asyncio:         1.6.0
numpy:                1.26.4
openpyxl:             3.1.2
pandas:               2.0.3
pyarrow:              15.0.0
pydantic:             2.7.0
pyiceberg:            <not installed>
sqlalchemy:           2.0.29
torch:                <not installed>
xlsx2csv:             0.8.2
xlsxwriter:           <not installed>
@heshamdar heshamdar added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jun 20, 2024
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