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

Panic with multiple outputs in then() #7031

Open
2 tasks done
2-5 opened this issue Feb 19, 2023 · 2 comments
Open
2 tasks done

Panic with multiple outputs in then() #7031

2-5 opened this issue Feb 19, 2023 · 2 comments
Labels
bug Something isn't working P-low Priority: low python Related to Python Polars

Comments

@2-5
Copy link
Contributor

2-5 commented Feb 19, 2023

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

then() typing seems to suggest that it supports multiple output expressions, but it panics if you try that.

def then(
    self,
    expr: (
        PolarsExprType
        | PythonLiteral
        | pli.Series
        | Iterable[PolarsExprType | PythonLiteral | pli.Series]
        | None
    ),
) -> WhenThen:

Reproducible example

import os

import polars as pl

os.environ["RUST_BACKTRACE"] = "full"

df = pl.DataFrame({
    "a": list(range(10)),
})
print(df)

df2 = df.with_columns([
    pl.when(pl.col("a") > 5).then([
        pl.lit(100).alias("b"),
        pl.lit(200).alias("c"),
    ]),
])
print(df2)

Outputs:

thread '<unnamed>' panicked at 'not implemented for dtype Object("object")', D:\a\polars\polars\polars\polars-core\src\series\ops\null.rs:59:17
stack backtrace:
   0:     0x7ff871a82310 - ffi_select_with_compiled_path
   1:     0x7ff8702f359b - BrotliDecoderVersion
   2:     0x7ff871a703ca - ffi_select_with_compiled_path
   3:     0x7ff871a83dbb - ffi_select_with_compiled_path
   4:     0x7ff871a839c8 - ffi_select_with_compiled_path
   5:     0x7ff871a84930 - ffi_select_with_compiled_path
   6:     0x7ff871a84386 - ffi_select_with_compiled_path
   7:     0x7ff871a842cf - ffi_select_with_compiled_path
   8:     0x7ff871a842a4 - ffi_select_with_compiled_path
   9:     0x7ff871b3e555 - ffi_select_with_compiled_path
  10:     0x7ff87049c51e - ffi_select_with_compiled_path
  11:     0x7ff8705085a2 - ffi_select_with_compiled_path
  12:     0x7ff8704ee4d4 - ffi_select_with_compiled_path
  13:     0x7ff8713170bd - ffi_select_with_compiled_path
  14:     0x7ff871369011 - ffi_select_with_compiled_path
  15:     0x7ff871bea8ca - ffi_select_with_compiled_path
  16:     0x7ff871987fa4 - ffi_select_with_compiled_path
  17:     0x7ff8719878ac - ffi_select_with_compiled_path
  18:     0x7ff871a8142c - ffi_select_with_compiled_path
  19:     0x7ff913bc7614 - BaseThreadInitThunk
  20:     0x7ff914aa26a1 - RtlUserThreadStart
Traceback (most recent call last):
  File "test.py", line 12, in <module>
    df2 = df.with_columns([
  File ".venv\lib\site-packages\polars\internals\dataframe\frame.py", line 6022, in with_columns
    self.lazy()
  File ".venv\lib\site-packages\polars\internals\lazyframe\frame.py", line 1148, in collect
    return pli.wrap_df(ldf.collect())
pyo3_runtime.PanicException: not implemented for dtype Object("object")

Expected behavior

Works? Or documented as not supporting multiple outputs.

Installed versions

---Version info---
Polars: 0.16.7
Index type: UInt32
Platform: Windows-10-10.0.19045-SP0
Python: 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)]
---Optional dependencies---
pyarrow: 11.0.0
pandas: 1.5.3
numpy: 1.23.5
fsspec: 2023.1.0
connectorx: <not installed>
xlsx2csv: <not installed>
deltalake: <not installed>
matplotlib: 3.7.0
@2-5 2-5 added bug Something isn't working python Related to Python Polars labels Feb 19, 2023
@universalmind303
Copy link
Collaborator

This still seems relevant as of 0.19.19. The type hints don't explicitly state that iterables are accepted, but as mentioned in #7040, we should allow them.

@universalmind303 universalmind303 added the accepted Ready for implementation label Dec 11, 2023
@stinodego stinodego added P-low Priority: low and removed accepted Ready for implementation labels Jan 12, 2024
@stinodego
Copy link
Member

The type signature has been updated since. But this still panics when it shouldn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-low Priority: low python Related to Python Polars
Projects
Status: Ready
Development

No branches or pull requests

3 participants