Repository navigation
fix: validate target columns before inference - #145
Open
sun-9545sunoj wants to merge 1 commit into
Open
sun-9545sunoj wants to merge 1 commit into
sun-9545sunoj wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
`target` was validated for presence only: `_require_columns` passes as long as every name is a column of `past`. A `target` that repeats a column, or that names the time column, was carried past the boundary and failed inside pandas at `past.loc[:, target]` with a message that never mentioned `target`: | target | before | | --- | --- | | `["sales", "sales"]` | `'DataFrame' object has no attribute 'dtype'` | | `["timestamp", "sales"]` | `"['timestamp'] not in index"` | | `["timestamp"]` | `"None of [Index(['timestamp'] ...)] are in the [columns]"` | `_check_target_columns` now rejects both shapes on `CoercedPredictRequest`, naming what was sent and what to send instead, so `POST /predict` and `POST /predict/bytes` behave the same and neither reaches an estimator. Column inference is unaffected: it takes the past columns other than `time` and those of `future`, which are unique and exclude `time` by construction. Fixes sktime#144
sun-9545sunoj
force-pushed
the
fix/validate-target-columns
branch
from
November 10, 2026 14:08
54bf407 to
a8617d2
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #144
targetwas validated for presence only._require_columnspasses as long as every name is a column ofpast, so atargetthat repeats a column, or that names the time column, was accepted byPredictRequest, accepted bycoerce_request, and then failed inside pandas atpast.loc[:, target]infrom_request. The caller got HTTP 400 carrying a raw pandas message that never mentionedtarget:target["sales", "sales"]'DataFrame' object has no attribute 'dtype'target repeats column(s) ['sales'].["timestamp", "sales"]"['timestamp'] not in index"target includes the time column 'timestamp'.["timestamp"]"None of [Index(['timestamp'], dtype='object')] are in the [columns]"target includes the time column 'timestamp'.A duplicated target was the worse of the two:
past.loc[:, ["sales", "sales"]]selects a two-column frame, so thedtypeAttributeErrorcame from sktime inspecting what it expected to be a Series.Change
_check_target_columnsintypes/_checks.pyrejects atargetthat containstime, and atargetthat repeats a column. Each message states the problem, then what to send instead, in the style the rest of the request contract uses:The suggested value is derived from what was sent, so
target=["sales", "promo", "sales"]suggeststarget=['sales', 'promo'].The check runs on
CoercedPredictRequest._check_frame_columns, so it coversPOST /predictandPOST /predict/bytestogether — the latter decodes straight into the coerced model without aPredictRequest, the same reason the quantile check had to live there in fix: validate quantiles in PredictRequest and CoercedPredictRequest #137.Both shapes are now rejected before any
fit/predict, so no inference pass is paid for a request that cannot work.Column inference is deliberately untouched: it takes the past columns other than
timeand those offuture, which are unique and excludetimeby construction, so it can produce neither shape.Tests
src/tserve/types/tests/test_models.py:test_coerced_request_rejects(duplicate, several duplicates, time plus a target, time alone);test_coerced_request_target_errors_name_what_to_send_instead, asserting each message carries the correctedtarget;test_coerced_request_keeps_distinct_target_columnsfor the valid multi-target path.src/tserve/server/tests/test_routes.py:test_predict_rejects_malformed_target_before_predict, which asserts HTTP 400 with the new message andscheduler.run.assert_not_called().ruff check,ruff format,tyandcodespellall pass via pre-commit. Docs updated inclient/data.md(column inference) andreference/errors.md(the 400 row).@geetu040 could you review this when you have a moment? Happy to adjust the wording of either message, or to move the check if you would rather have it somewhere else in the contract.