Минимальный рабочий пример действительно минимален, просто вызовите read_excel:
Код: Выделить всё
from pathlib import Path
import polars as pl
root = Path("/path/to/globdir")
def try_to_open():
for file in root.rglob("*/*_fileID.xlsx"):
print(f"\r{file.name}", end='')
try:
df = pl.read_excel(file, engine="calamine", infer_schema_length=0)
except Exception as e:
print(f"{file.name}: {e}", flush=True)
def main():
try_to_open()
if __name__ == "__main__":
main()
Код: Выделить всё
thread '' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calamine-0.26.1/src/xlsx/cells_reader.rs:347:39:
index out of bounds: the len is 2585 but the index is 2585
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "/path/to/script.py", line 18, in
main()
File "/path/to/script.py", line 15, in main
try_to_open()
File "/path/to/script.py", line 10, in try_to_open
df = pl.read_excel(file, engine="calamine", infer_schema_length=0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/polars/_utils/deprecation.py", line 92, in wrapper
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/polars/_utils/deprecation.py", line 92, in wrapper
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/polars/io/spreadsheet/functions.py", line 299, in read_excel
return _read_spreadsheet(
^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/polars/io/spreadsheet/functions.py", line 536, in _read_spreadsheet
name: reader_fn(
^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/polars/io/spreadsheet/functions.py", line 951, in _read_spreadsheet_calamine
ws_arrow = parser.load_sheet_eager(sheet_name, **read_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/fastexcel/__init__.py", line 394, in load_sheet_eager
return self._reader.load_sheet(
^^^^^^^^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: index out of bounds: the len is 2585 but the index is 2585
Я хочу иметь возможность перехватывать имя файла, в котором произошел сбой. Есть ли способ заставить дочерние потоки Calamine сворачиваться и возвращать код ошибки вместо того, чтобы все разрушать?
Подробнее здесь: https://stackoverflow.com/questions/792 ... gracefully