Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/autogluon/cloud/scripts/sagemaker_scripts/tabular_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,23 @@ def _read_with_fallback(read_func, buf, expected_columns):
"""
# Attempt to read with headers
data = read_func(buf)
if set(data.columns) != set(expected_columns):
# Reset buffer and read without headers
buf.seek(0)
data = read_func(buf, header=None)
# Assign expected column names
data.columns = expected_columns
else:
data_cols, model_cols = set(data.columns), set(expected_columns)
required_fields_missing = model_cols.difference(data_cols)

if required_fields_missing:
raise ValueError("Missing required columns", required_fields_missing)

if data_cols == model_cols:
# Reorder columns to match expected_columns
data = data[expected_columns]
return data

# Reset buffer and read without headers
buf.seek(0)
data = read_func(buf, header=None)
# Assign expected column names
data.columns = expected_columns

return data


Expand Down
Loading