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

InvalidOperationError on trying to select array with pl.lit #18709

Closed
2 tasks done
Kryzpoo opened this issue Sep 12, 2024 · 2 comments
Closed
2 tasks done

InvalidOperationError on trying to select array with pl.lit #18709

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

Comments

@Kryzpoo
Copy link

Kryzpoo commented Sep 12, 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

df1 = pl.DataFrame(dict(id=[1, 2, 3]))
df1.select(id=pl.col('id'), aggs=pl.lit([]))

Log output

Traceback (most recent call last):
  File "/root/.pycharm_helpers/pydevd_asyncio/pydevd_asyncio_utils.py", line 117, in _exec_async_code
    result = func()
             ^^^^^^
  File "<input>", line 1, in <module>
  File "/usr/local/lib/python3.11/site-packages/polars/dataframe/frame.py", line 8968, in select
    return self.lazy().select(*exprs, **named_exprs).collect(_eager=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/polars/lazyframe/frame.py", line 2034, in collect
    return wrap_df(ldf.collect(callback))
                   ^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.InvalidOperationError: Series: aggs, length 1 doesn't match the DataFrame height of 3
If you want this Series to be broadcasted, ensure it is a scalar (for instance by adding '.first()').

Issue description

Problem appeared in polars 1.7: when i'm trying to append to DF a constant array column

Expected behavior

In 1.6, i would get DF with constant array column:

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

Installed versions

pl.show_versions()
--------Version info---------
Polars:              1.7.0
Index type:          UInt32
Platform:            Linux-5.15.49-linuxkit-pr-aarch64-with-glibc2.28
Python:              3.11.4 (main, Jun 13 2023, 11:34:58) [GCC 8.3.0]

@Kryzpoo Kryzpoo added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Sep 12, 2024
@ritchie46
Copy link
Member

fixed by #18707

I shall patch

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

3 participants