From acb601d6ce0608e72cae22b1b24ea275e743173b Mon Sep 17 00:00:00 2001 From: wsyxbcl Date: Tue, 7 May 2024 23:31:39 +0800 Subject: [PATCH] fix(python): Improve error handling of `ParameterCollisionError` in `read_excel` (#16100) --- py-polars/polars/io/spreadsheet/functions.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/py-polars/polars/io/spreadsheet/functions.py b/py-polars/polars/io/spreadsheet/functions.py index 2a77037eb588..2947129fd175 100644 --- a/py-polars/polars/io/spreadsheet/functions.py +++ b/py-polars/polars/io/spreadsheet/functions.py @@ -503,13 +503,17 @@ def _read_spreadsheet( # normalise some top-level parameters to 'read_options' entries if engine == "calamine": - if "schema_sample_rows" in read_options: + if ("schema_sample_rows" in read_options) and ( + infer_schema_length != N_INFER_DEFAULT + ): msg = 'cannot specify both `infer_schema_length` and `read_options["schema_sample_rows"]`' raise ParameterCollisionError(msg) read_options["schema_sample_rows"] = infer_schema_length elif engine == "xlsx2csv": - if "infer_schema_length" in read_options: + if ("infer_schema_length" in read_options) and ( + infer_schema_length != N_INFER_DEFAULT + ): msg = 'cannot specify both `infer_schema_length` and `read_options["infer_schema_length"]`' raise ParameterCollisionError(msg) read_options["infer_schema_length"] = infer_schema_length