fix: replace NotImplementedError in _surveillance_flags with graceful fallback#1207
Open
khushthecoder wants to merge 7 commits intomalariagen:masterfrom
Open
Conversation
… fallback (fixes malariagen#1206) Made-with: Cursor
Made-with: Cursor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1207 +/- ##
==========================================
+ Coverage 89.46% 89.48% +0.02%
==========================================
Files 51 51
Lines 6008 6020 +12
==========================================
+ Hits 5375 5387 +12
Misses 633 633 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
Fixes #1206. The abstract method
_surveillance_flagsinAnophelesBasepreviously raisedNotImplementedErrorwhen a subclass did not implement it. For new species resources or minimal subclasses during development, this caused a hard crash instead of a clear warning and graceful fallback. This PR replaces the raise with a fallback that returns an empty DataFrame with the expected schema and emits aUserWarning.Problem
When
_surveillance_flagsis not overridden (e.g. during development of a new species or when using a minimal subclass ofAnophelesBase), any call that reaches this method raisesNotImplementedError. The crash occurs in several paths:_relevant_sample_sets()whensurveillance_use_only=Truefilters sample sets via_sample_set_has_surveillance_data(), which calls_surveillance_flags()sample_metadata()merges surveillance flags via_surveillance_flags()wgs_data_catalog()whensurveillance_use_only=TrueIn contrast,
_parse_surveillance_flagsinsample_metadata.pyalready handles missing surveillance data (FileNotFoundError) by returning an empty DataFrame and emitting aUserWarning. The base stub now follows the same pattern.Changes
malariagen_data/anoph/base.py
import warningsraise NotImplementedError(...)in_surveillance_flagswith a graceful fallback that:UserWarningwith message:"Surveillance flags not implemented for this resource; returning empty data."(usesstacklevel=2so the warning points to the caller)pd.DataFramewith columnssample_id(object) andis_surveillance(nullable boolean), matching the schema expected by downstream codetests/anoph/test_base.py
TestSurveillanceFlagsBaseFallbackwith two tests:test_surveillance_flags_base_returns_empty_and_warns: Asserts that the base implementation returns an empty DataFrame with correct columns and dtypes and emitsUserWarningtest_sample_set_has_surveillance_data_returns_false_when_fallback: Asserts that_sample_set_has_surveillance_data()returnsFalsewhen the base fallback is used (empty DataFrame →.any()is False)Compatibility
_prep_sample_sets_param()orgeneral_metadata().sample_idandis_surveillancecolumns receives that structure; empty DataFrame makes merges harmless and.any()False.AnophelesSampleMetadata._surveillance_flags()overrides the base and continues to load real data; all full species (Ag3, Af1, Adir1, etc.) use that implementation.Impact
_parse_surveillance_flags(missing data → warn + empty DataFrame).