Skip to content

Commit 1d2543f

Browse files
committed
SNOW-3385961: simplify INFER_SCHEMA zero-row error message
Trim the multi-line comment to a single 3-line note, replace the manual option-hint loop with a list comprehension, and shorten the error message without losing the "path missing or format-option-filtered" information.
1 parent 94d19cb commit 1d2543f

1 file changed

Lines changed: 12 additions & 23 deletions

File tree

src/snowflake/snowpark/dataframe_reader.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,31 +1338,20 @@ def _infer_schema_for_file_format(
13381338
raise e
13391339

13401340
if len(results) == 0:
1341-
# Zero rows from INFER_SCHEMA can mean the path is empty/missing,
1342-
# or that file format options silently filtered every row/header
1343-
# (e.g. PARSE_HEADER on a file with a leading blank line,
1344-
# SKIP_HEADER exceeding row count, or ON_ERROR=CONTINUE dropping
1345-
# bad rows). Surface both possibilities so callers don't chase a
1346-
# phantom path-not-found issue when the real cause is a format
1347-
# option.
1348-
option_hints = []
1349-
for key in ("PARSE_HEADER", "SKIP_HEADER", "ON_ERROR"):
1350-
if key in format_type_options:
1351-
option_hints.append(f"{key}={format_type_options[key]}")
1352-
elif key in infer_schema_options:
1353-
option_hints.append(f"{key}={infer_schema_options[key]}")
1354-
hint_suffix = (
1355-
f" Applied file format options: {', '.join(option_hints)}."
1356-
if option_hints
1357-
else ""
1358-
)
1341+
# Zero rows can mean the path is empty/missing, or that file
1342+
# format options (PARSE_HEADER, SKIP_HEADER, ON_ERROR=CONTINUE)
1343+
# silently filtered everything out.
1344+
hints = [
1345+
f"{k}={format_type_options.get(k, infer_schema_options.get(k))}"
1346+
for k in ("PARSE_HEADER", "SKIP_HEADER", "ON_ERROR")
1347+
if k in format_type_options or k in infer_schema_options
1348+
]
1349+
suffix = f" Applied options: {', '.join(hints)}." if hints else ""
13591350
raise FileNotFoundError(
13601351
f"Given path: '{path}' returned no results from INFER_SCHEMA. "
1361-
"The path may be empty or missing, or file format options may "
1362-
"have filtered every row/header (e.g. PARSE_HEADER on a file "
1363-
"with a leading blank line, SKIP_HEADER exceeding row count, "
1364-
"or ON_ERROR=CONTINUE silently dropping bad rows). Check the "
1365-
"file contents and file format options." + hint_suffix
1352+
"The path may be empty/missing, or file format options may "
1353+
"have filtered every row/header. Check the file contents and "
1354+
"file format options." + suffix
13661355
)
13671356
new_schema = []
13681357
schema_to_cast = []

0 commit comments

Comments
 (0)