Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

.implode().list method is not valid before .over. #18225

Closed
2 tasks done
PierXuY opened this issue Aug 16, 2024 · 4 comments
Closed
2 tasks done

.implode().list method is not valid before .over. #18225

PierXuY opened this issue Aug 16, 2024 · 4 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@PierXuY
Copy link

PierXuY commented Aug 16, 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.DataFrame({
    'type': ['water','fire','water','earth']
})


out1 = df.select(
    pl.col('type').implode().over("type", mapping_strategy="explode").list.first()
)
print(out1)

# shape: (3, 1)
# ┌───────┐
# │ type  │
# │ ---   │
# │ str   │
# ╞═══════╡
# │ water │
# │ fire  │
# │ earth │
# └───────┘

# The code above works, but the expression below that I think is equivalent throws an error.

out2 = df.select(
    pl.col('type').implode().list.first().over("type", mapping_strategy="explode")
)
print(out2)
# InvalidOperationError: 'implode' followed by an aggregation is not allowed

Log output

No response

Issue description

The example is from another issue, and according to the issue, this expression was legal in earlier versions of polars.

In addition, the error reported in the current polars version is also confusing.
In code that works fine:

out1 = df.select(
    pl.col('type').implode().over("type", mapping_strategy="explode").list.first()
)
print(out1)

'implode' followed by an aggregation is allowed.

But another code pl.col('type').implode().list.first().over("type", mapping_strategy="explode") reports an error: InvalidOperationError: 'implode' followed by an aggregation is not allowed.

Expected behavior

I think both expressions should be able to execute normally. If the error code is unreasonable, there should be a more accurate error message.

Installed versions

--------Version info---------
Polars:               1.5.0
Index type:           UInt32
Platform:             Windows-10-10.0.22631-SP0
Python:               3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]

----Optional dependencies----
adbc_driver_manager:  1.1.0
cloudpickle:          3.0.0
connectorx:           0.3.3
deltalake:            0.19.0
fastexcel:            0.11.5
fsspec:               2024.6.1
gevent:               24.2.1
great_tables:         0.10.0
hvplot:               0.10.0
matplotlib:           3.9.2
nest_asyncio:         1.6.0
numpy:                2.0.1
openpyxl:             3.1.5
pandas:               2.2.2
pyarrow:              17.0.0
pydantic:             2.8.2
pyiceberg:            0.7.0
sqlalchemy:           2.0.32
torch:                <not installed>
xlsx2csv:             0.8.3
xlsxwriter:           3.2.0
@PierXuY PierXuY added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Aug 16, 2024
@PierXuY PierXuY changed the title ExprListNameSpace method is not valid before .over. .implode().list method is not valid before .over. Aug 16, 2024
@ritchie46
Copy link
Member

It is not a bug, we don't allow this operation, hence the error.

@PierXuY
Copy link
Author

PierXuY commented Aug 16, 2024

It is not a bug, we don't allow this operation, hence the error.

It seems that #18228 is related to this reason.

@ritchie46
Copy link
Member

Yes, that one is the samse story. Not allowed for now. There is complexity in that, that I don't want to get into for now.

@ritchie46
Copy link
Member

I will close this as this is not a bug.

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