polars.exceptions.ColumnNotFoundError when coerce=True and Optional field is missing #1804
Open
2 of 3 tasks
Labels
bug
Something isn't working
Describe the bug
A clear and concise description of what the bug is.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Exception:
(.venv) antonioalegria@shiro dojo % /Users/antonioalegria/Developer/dojo/.venv/bin/python /Users/antonioalegria/Developer/dojo/dojo/test.py
Traceback (most recent call last):
File ".../test.py", line 22, in
print(schema.validate(df))
^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.12/site-packages/pandera/api/polars/container.py", line 58, in validate
output = self.get_backend(check_obj).validate(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.12/site-packages/pandera/backends/polars/container.py", line 63, in validate
check_obj = parser(check_obj, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.12/site-packages/pandera/backends/polars/container.py", line 396, in coerce_dtype
check_obj = self._coerce_dtype_helper(check_obj, schema)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.12/site-packages/pandera/backends/polars/container.py", line 455, in _coerce_dtype_helper
obj = getattr(col_schema.dtype, coerce_fn)(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.12/site-packages/pandera/engines/polars_engine.py", line 181, in try_coerce
lf.collect()
File ".../.venv/lib/python3.12/site-packages/polars/lazyframe/frame.py", line 2034, in collect
return wrap_df(ldf.collect(callback))
^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.ColumnNotFoundError: a
Expected behavior
The dataframe should've been validated.
Desktop (please complete the following information):
OS: macOS 14.6.1
Python 3.12.4
polars-lts-cpu 1.6.0
pandera 0.20.3
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: