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

min / max_horizontal PanicException for mixed types #21835

Open
2 tasks done
cmdlineluser opened this issue Mar 18, 2025 · 1 comment · May be fixed by #21857
Open
2 tasks done

min / max_horizontal PanicException for mixed types #21835

cmdlineluser opened this issue Mar 18, 2025 · 1 comment · May be fixed by #21857
Labels
A-panic Area: code that results in panic exceptions accepted Ready for implementation bug Something isn't working P-low Priority: low python Related to Python Polars

Comments

@cmdlineluser
Copy link
Contributor

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({"x": [1, 2], "y": ["three", "four"]})

df.select(pl.min_horizontal("x", "y"))
# PanicException: not implemented for dtype String

Log output

Issue description

If the String column is last the expected error is raised.

df.select(pl.min_horizontal("y", "x"))
# ComputeError: cannot compare string with numeric type (i64)

Expected behavior

ComputeError

Installed versions

--------Version info---------
Polars:              1.25.2
Index type:          UInt32
Platform:            macOS-13.6.1-arm64-arm-64bit-Mach-O
Python:              3.13.0 (main, Oct  7 2024, 05:02:14) [Clang 15.0.0 (clang-1500.1.0.2.5)]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
boto3                <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            0.12.0
fsspec               <not installed>
gevent               <not installed>
google.auth          <not installed>
great_tables         0.14.0
matplotlib           <not installed>
nest_asyncio         <not installed>
numpy                2.1.3
openpyxl             3.1.5
pandas               2.2.3
pyarrow              18.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           3.2.0
@cmdlineluser cmdlineluser added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Mar 18, 2025
@orlp orlp added P-low Priority: low A-panic Area: code that results in panic exceptions accepted Ready for implementation and removed needs triage Awaiting prioritization by a maintainer labels Mar 18, 2025
@kdn36
Copy link
Contributor

kdn36 commented Mar 19, 2025

Easily reproducible in Rust. This looks straightforward to fix in the code, and I would like to give it a try.

Code snippet

    let df = df!(
        "x" => [1, 2],
        "y" => ["three", "four"])
    .unwrap();

    let result = df.select(["x", "y"])?.min_horizontal();
    println!("result: {:?}", result);
    Ok(())

gives

thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/polars-ops-0.46.0/src/series/ops/horizontal.rs:107:17:
not implemented for dtype String
stack backtrace:
   0: rust_begin_unwind
             at /rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library/std/src/panicking.rs:692:5
   1: core::panicking::panic_fmt
             at /rustc/4d91de4e48198da2e33413efdcd9cd2cc0c46688/library/core/src/panicking.rs:75:14
   2: polars_ops::series::ops::horizontal::min_max_binary_columns
             at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/polars-ops-0.46.0/src/series/ops/horizontal.rs:107:17
   3: polars_ops::series::ops::horizontal::min_horizontal::{{closure}}
             at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/polars-ops-0.46.0/src/series/ops/horizontal.rs:170:45
   4: polars_ops::series::ops::horizontal::min_horizontal
             at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/polars-ops-0.46.0/src/series/ops/horizontal.rs:175:14
   5: <polars_core::frame::DataFrame as polars_ops::series::ops::horizontal::MinMaxHorizontal>::min_horizontal
             at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/polars-ops-0.46.0/src/series/ops/horizontal.rs:34:9
   6: issue_21835::main
             at ./src/main.rs:12:18
   7: core::ops::function::FnOnce::call_once
             at /root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-panic Area: code that results in panic exceptions accepted Ready for implementation bug Something isn't working P-low Priority: low python Related to Python Polars
Projects
None yet
3 participants