feat: Add user warning for empty sample metadata query (fixes #1083)#1088
Open
Gopisokk wants to merge 2 commits intomalariagen:masterfrom
Open
feat: Add user warning for empty sample metadata query (fixes #1083)#1088Gopisokk wants to merge 2 commits intomalariagen:masterfrom
Gopisokk wants to merge 2 commits intomalariagen:masterfrom
Conversation
…cklevel, and catching pre-query states correctly. added edge-case tests.
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.
What problem does this solve?
When querying sample metadata using a
pandasquery string in the wrong case (e.g.country == 'uganda'instead ofcountry == 'Uganda'), the API silently returns zero results. This can prove challenging to researchers and health workers when they input the queries, especially those unfamiliar with the exact string formatting required by the API.This PR ensures that when a query filters out all records and results in an empty DataFrame, the API emits a helpful
UserWarningexplicitly informing the user that string matching is case-sensitive. It also updates the docstrings coveringsample_queryto clarify this behavior.How does it solve it?
UserWarning: Inside sample_metadata() (where the DataFrame query is executed), we now check the length of the DataFrame before and after the query is applied. If the DataFrame goes from non-empty to empty, aUserWarningis raised to inform the user about the case-sensitivity issue.sample_queryTypeAlias documentation in base_params.py.Relevant issue numbers
Closes #1083
Testing done
poetry run pytest -v tests/anoph/test_sample_metadata.py -k "test_sample_metadata_empty_query_warning").ruffstandards and all pre-commit hooks passed.Any breaking changes or migration notes
None. This is purely a UX enhancement designed to catch errors caused by capitalization mismatches in queries!