diff --git a/CHANGELOG.md b/CHANGELOG.md index 435d6af6dd..9b902b13ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ #### Bug Fixes - Fixed a bug where using parameter bindings for `CALL` queries issued through `session.sql` would raise an error. +- Improved the `FileNotFoundError` message raised when `INFER_SCHEMA` returns zero rows so it also points to file format options (`PARSE_HEADER`, `SKIP_HEADER`, `ON_ERROR=CONTINUE`) that can silently filter everything out, instead of only suggesting a missing path. ## 1.50.0 (2026-04-23) diff --git a/src/snowflake/snowpark/dataframe_reader.py b/src/snowflake/snowpark/dataframe_reader.py index b13d3c33b2..f435e9a1b4 100644 --- a/src/snowflake/snowpark/dataframe_reader.py +++ b/src/snowflake/snowpark/dataframe_reader.py @@ -1338,8 +1338,20 @@ def _infer_schema_for_file_format( raise e if len(results) == 0: + # Zero rows can mean the path is empty/missing, or that file + # format options (PARSE_HEADER, SKIP_HEADER, ON_ERROR=CONTINUE) + # silently filtered everything out. + hints = [ + f"{k}={format_type_options.get(k, infer_schema_options.get(k))}" + for k in ("PARSE_HEADER", "SKIP_HEADER", "ON_ERROR") + if k in format_type_options or k in infer_schema_options + ] + suffix = f" Applied options: {', '.join(hints)}." if hints else "" raise FileNotFoundError( - f"Given path: '{path}' could not be found or is empty." + f"Given path: '{path}' returned no results from INFER_SCHEMA. " + "The path may be empty/missing, or file format options may " + "have filtered every row/header. Check the file contents and " + "file format options." + suffix ) new_schema = [] schema_to_cast = [] diff --git a/tests/integ/scala/test_dataframe_reader_suite.py b/tests/integ/scala/test_dataframe_reader_suite.py index 6f0cae72e5..4d62e6a16a 100644 --- a/tests/integ/scala/test_dataframe_reader_suite.py +++ b/tests/integ/scala/test_dataframe_reader_suite.py @@ -2119,18 +2119,23 @@ def test_filepath_not_exist_or_empty(session): session.read.option("PARSE_HEADER", True).option("INFER_SCHEMA", True).csv( empty_file_path ) - assert f"Given path: '{empty_file_path}' could not be found or is empty." in str( - ex_info + assert ( + f"Given path: '{empty_file_path}' returned no results from INFER_SCHEMA." + in str(ex_info.value) ) + # Message should mention file format options so users don't chase a phantom + # path-not-found when the real cause is PARSE_HEADER/SKIP_HEADER/ON_ERROR. + assert "file format options" in str(ex_info.value) with pytest.raises(FileNotFoundError) as ex_info: session.read.option("PARSE_HEADER", True).option("INFER_SCHEMA", True).csv( not_exist_file_path ) assert ( - f"Given path: '{not_exist_file_path}' could not be found or is empty." - in str(ex_info) + f"Given path: '{not_exist_file_path}' returned no results from INFER_SCHEMA." + in str(ex_info.value) ) + assert "file format options" in str(ex_info.value) @pytest.mark.skipif(