Fix test_vasopressor_units AttributeError (Series has no .contains)#1994
Open
Chessing234 wants to merge 1 commit intoMIT-LCP:mainfrom
Open
Fix test_vasopressor_units AttributeError (Series has no .contains)#1994Chessing234 wants to merge 1 commit intoMIT-LCP:mainfrom
Chessing234 wants to merge 1 commit intoMIT-LCP:mainfrom
Conversation
test_vasopressor_units branches on '(~df["hadm_id"].contains(hadm_id_list)).any()', but pandas Series has no .contains() method - only Series.str.contains for string matching. The intended check is 'hadm_id is not in the known list', which is Series.isin(...). As written, the call raises 'AttributeError: Series object has no attribute contains' whenever df is not empty, so the test cannot reach its assertion whenever mimic-iv contains any non-standard-unit rows for these drugs. Swap .contains() for .isin() so the membership test works as intended.
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.
Bug
test_vasopressor_unitsinmimic-iv/tests/test_medication.pyraisesAttributeError: 'Series' object has no attribute 'contains'whenever the inner query returns any rows:https://github.com/MIT-LCP/mimic-code/blob/5706978/mimic-iv/tests/test_medication.py#L60-L61
Root cause
pandas.Serieshas no.contains()method. The string accessorSeries.str.containsexists for substring matching on strings, but the intent here is clearly "is each hadm_id in the known list of manually-inspected hadm_ids", which isSeries.isin(hadm_id_list).Fix
Replace
.contains(hadm_id_list)with.isin(hadm_id_list). The~…any()negation and the surrounding logic then work as intended: the warning fires when a row has anhadm_idnot already on the allow-list, which is the documented behaviour of the surrounding comment ("if we find new uninspected rows, raise a warning").