polars icon indicating copy to clipboard operation
polars copied to clipboard

`map_elements` silently swallows Exceptions when `return_dtype=` is set

Open cmdlineluser opened this issue 4 months ago • 0 comments

Checks

  • [X] I have checked that this issue has not already been reported.
  • [X] I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import polars as pl

pl.select(
    pl.lit(1).map_elements(lambda x: 
        I | DO | NOT | EXIST,
        return_dtype=pl.String
    )
)

# shape: (1, 1)
# ┌─────────┐
# │ literal │
# │ ---     │
# │ str     │
# ╞═════════╡
# │ null    │
# └─────────┘

Log output

No response

Issue description

I previously encountered this while debugging a related issue: https://github.com/pola-rs/polars/issues/14821#issuecomment-2377147733 (some notes there)

Breaking out as a separate issue as I just ran into a confusing few minutes due to it.

Expected behavior

.map_batches propagates the error.

# ComputeError: NameError: name 'I' is not defined

Installed versions

--------Version info---------
Polars:               1.9.0
Index type:           UInt32
Platform:             macOS-13.6.1-arm64-arm-64bit
Python:               3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         <not installed>
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.1
pyarrow:              15.0.2
pydantic:             <not installed>
pyiceberg:            <not installed>
sqlalchemy:           <not installed>
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>

cmdlineluser avatar Oct 19 '24 10:10 cmdlineluser