Return empty series instead of an HTTP 500 when compute_node_series has no observations - #218
Open
eastagiletracker wants to merge 1 commit into
Conversation
…no observations POST /data/compute_node_series raised a KeyError (HTTP 500) for an empty request body ([]) or a series with no points ([[]]): the resulting empty dataframe has no node-variable columns to select. Return empty median/q0.25/q0.75 series in that case instead. Also add the api/swotvis/tests pytest suite that the `make test` target already invokes but which did not exist, covering the normal computation and this empty-input regression.
👷 Deploy request for swotviz pending review.Visit the deploys page to approve it
|
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.
This PR proposes fixing an HTTP 500 in the
/data/compute_node_seriesnode-statistics endpoint when it receives no observations, and adding the backendpytestsuite that yourmake testtarget runs. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/198. You can sign in with your GitHub ID to claim ownership of the project.The fix
When a request to
POST /data/compute_node_seriescarries no node observations — an empty body[], or a series with no points[[]]—SwotNodeDataSeriesModel.as_dataframe()builds an emptyDataFramewith no columns, and the very next[NodeVariables.list()]column selection raises aKeyError, which FastAPI surfaces to the caller as a 500.Reproduced on
developat HEAD (fddb1e0), using the samepython:3.10/pandas==2.2.2/fastapi==0.111.1the API container pins:The traceback is
KeyError: "None of [Index(['wse', 'width', 'area_total', 'p_dist_out'], dtype='object')] are in the [columns]".The statistics feature reaches this endpoint from
stores/stats.jsgetStatistics(), which posts the visibleswot_node_seriesdatasets' points; that list is empty whenever no node series is currently visible, or when time-range / data-quality filtering has removed every point. Your open PR #210 already adds a front-end guard for one of these paths (recomputeStatsAndUpdateCharts), which is what pointed me at the failure mode — this change is complementary and hardens the endpoint itself, so the API no longer 500s regardless of what the client sends.The fix materializes the dataframe once and, when it is empty, returns
{"median": [], "q0.25": [], "q0.75": []}— the same response shape as the success path, so the front end'sgenerateStatisticsSeriesloop simply builds no series. The non-empty path is unchanged, so existing behavior is preserved.I also added the
api/swotvis/tests/suite that yourMakefiletesttarget (docker compose exec api pytest tests) already invokes but which did not exist yet, and addedpytesttorequirements-dev.txt. The suite covers the normal computation (median = 15.0 and quartiles 12.5 / 17.5 for two observations of 10 and 20 at one distance) plus the two empty-input regressions.Verification: the new tests fail against current
develop(2 failed, 1 passed— the empty-input cases 500) and pass with the fix (3 passed), run exactly asmake testruns them (pytest testsfrom/swotvis). Your pinnedisort==5.13.2andblack -S -l 120report no changes on the touched files. The rest of the repo is untouched — this is a backend-only change.How this was managed
This work was tracked as a story on a live agile board we imported from this repository's own issues and pull requests (217 stories, 8 labels): https://eastagiletracker.com/projects/198/stories/62015 — and the board itself, showing your project's history, lives at https://eastagiletracker.com/projects/198.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com