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

pl.repeat() panicks if input doesn't match data type #15379

Closed
2 tasks done
etiennebacher opened this issue Mar 28, 2024 · 2 comments · Fixed by #15387
Closed
2 tasks done

pl.repeat() panicks if input doesn't match data type #15379

etiennebacher opened this issue Mar 28, 2024 · 2 comments · Fixed by #15387
Labels
A-input-parsing Area: parsing input arguments A-panic Area: code that results in panic exceptions bug Something isn't working P-low Priority: low python Related to Python Polars

Comments

@etiennebacher
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
>>> pl.repeat([1, 2], n=2)
thread 'python3' panicked at py-polars/src/functions/lazy.rs:454:36:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/etienne/.local/lib/python3.10/site-packages/polars/functions/repeat.py", line 143, in repeat
    expr = wrap_expr(plr.repeat(value, n._pyexpr, dtype))
pyo3_runtime.PanicException: called `Option::unwrap()` on a `None` value

Log output

No response

Issue description

pl.repeat() panicks when input length is greater than 1.

Expected behavior

Not panick but throw an error instead.

Installed versions

--------Version info---------
Polars:               0.20.17
Index type:           UInt32
Platform:             Linux-6.5.0-21-generic-x86_64-with-glibc2.35
Python:               3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]

----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>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         <not installed>
numpy:                1.21.5
openpyxl:             <not installed>
pandas:               <not installed>
pyarrow:              <not installed>
pydantic:             <not installed>
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@etiennebacher etiennebacher added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Mar 28, 2024
@mcrumiller
Copy link
Contributor

The issue is that your value is a list. This actually works if you specify the dtype properly:

import polars as pl

pl.select(
    pl.repeat([1, 2], n=2, dtype=pl.List(pl.Int32))
)

# shape: (2, 1)
# ┌───────────┐
# │ repeat    │
# │ ---       │
# │ list[i32] │
# ╞═══════════╡
# │ [1, 2]    │
# │ [1, 2]    │
# └───────────┘

However, the error message should probably be more informative.

@etiennebacher
Copy link
Contributor Author

etiennebacher commented Mar 28, 2024

Thanks for the workaround, but the problem here isn't that the code doesn't work but that it panicks instead of having a proper error (cf #14463)

@etiennebacher etiennebacher changed the title pl.repeat() panicks if input length > 1 pl.repeat() panicks if input doesn't match data type Mar 28, 2024
@stinodego stinodego added A-panic Area: code that results in panic exceptions P-low Priority: low labels Mar 28, 2024
@github-project-automation github-project-automation bot moved this to Ready in Backlog Mar 28, 2024
@stinodego stinodego added A-input-parsing Area: parsing input arguments and removed needs triage Awaiting prioritization by a maintainer labels Mar 28, 2024
@github-project-automation github-project-automation bot moved this from Ready to Done in Backlog Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-input-parsing Area: parsing input arguments A-panic Area: code that results in panic exceptions bug Something isn't working P-low Priority: low python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants