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

pyo3_runtime.PanicException is raised instead of polars.exceptions.ColumnNotFoundError #14881

Closed
2 tasks done
vaghinak-vardanyan opened this issue Mar 6, 2024 · 0 comments · Fixed by #20720
Closed
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@vaghinak-vardanyan
Copy link

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

column_mapping = {
    "sample_c": "unit",
}
sample_lf = pl.scan_csv("sample.csv")
sample_lf = sample_lf.select(pl.col(column_mapping.keys())).collect()
sample_lf = sample_lf.rename(column_mapping)

sample.csv

Log output

thread '<unnamed>' panicked at /home/runner/work/polars/polars/crates/polars-lazy/src/frame/mod.rs:432:37:
called `Result::unwrap()` on an `Err` value: ColumnNotFound(ErrString("sample_c\n\nError originated just after this operation:\n\n  Csv SCAN sample.csv\n  PROJECT */2 COLUMNS"))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/home/vvardanyan/Projects/Portmind/declarant-app/declaire-spreadsheets/temp.py", line 8, in <module>
    sample_lf = sample_lf.rename(column_mapping)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vvardanyan/.cache/pypoetry/virtualenvs/declaire-spreadsheets-aN0ck--n-py3.11/lib/python3.11/site-packages/polars/lazyframe/frame.py", line 4478, in rename
    return self._from_pyldf(self._ldf.rename(existing, new))
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: ColumnNotFound(ErrString("sample_c\n\nError originated just after this operation:\n\n  Csv SCAN sample.csv\n  PROJECT */2 COLUMNS"))

Issue description

When select and then rename are called on LazyFrame with a column that doesn't exist in the file, pyo3_runtime.PanicException is being raised.

Expected behavior

ColumnNotFoundError should be raised.

polars.exceptions.ColumnNotFoundError: sample_c

Error originated just after this operation:

  Csv SCAN sample.csv
  PROJECT */2 COLUMNS

Installed versions

--------Version info---------
Polars:               0.20.13
Index type:           UInt32
Platform:             Linux-5.14.0-1034-oem-x86_64-with-glibc2.35
Python:               3.11.8 (main, Feb 25 2024, 16:39:33) [GCC 11.4.0]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               <not installed>
pyarrow:              15.0.0
pydantic:             2.6.2
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@vaghinak-vardanyan vaghinak-vardanyan added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Mar 6, 2024
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

Successfully merging a pull request may close this issue.

1 participant