Skip to content

feat: Add user warning for empty sample metadata query (fixes #1083)#1088

Open
Gopisokk wants to merge 2 commits intomalariagen:masterfrom
Gopisokk:GH1083-sample-metadata-warning
Open

feat: Add user warning for empty sample metadata query (fixes #1083)#1088
Gopisokk wants to merge 2 commits intomalariagen:masterfrom
Gopisokk:GH1083-sample-metadata-warning

Conversation

@Gopisokk
Copy link
Copy Markdown

@Gopisokk Gopisokk commented Mar 9, 2026

What problem does this solve?

When querying sample metadata using a pandas query string in the wrong case (e.g. country == 'uganda' instead of country == '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 UserWarning explicitly informing the user that string matching is case-sensitive. It also updates the docstrings covering sample_query to clarify this behavior.

How does it solve it?

  1. Added 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, a UserWarning is raised to inform the user about the case-sensitivity issue.
  2. Documentation Update: Merged an explicitly worded note about case-sensitive string matching into the sample_query TypeAlias documentation in base_params.py.
  3. Testing: Implemented test_sample_metadata_empty_query_warning in tests/anoph/test_sample_metadata.py to assert that an empty query successfully raises the expected warning message.

Relevant issue numbers

Closes #1083

Testing done

  • Ran local unit tests specifically for the warning logic implementation (poetry run pytest -v tests/anoph/test_sample_metadata.py -k "test_sample_metadata_empty_query_warning").
  • All broader unit tests using simulated data passed successfully.
  • Code matches ruff standards 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sample_metadata() silently returns empty DataFrame for case-mismatched string queries on country/location with no warning or suggestion

1 participant