Skip to content

Fix test_vasopressor_units AttributeError (Series has no .contains)#1994

Open
Chessing234 wants to merge 1 commit intoMIT-LCP:mainfrom
Chessing234:fix/test-medication-hadm-id-contains-isin
Open

Fix test_vasopressor_units AttributeError (Series has no .contains)#1994
Chessing234 wants to merge 1 commit intoMIT-LCP:mainfrom
Chessing234:fix/test-medication-hadm-id-contains-isin

Conversation

@Chessing234
Copy link
Copy Markdown

Bug

test_vasopressor_units in mimic-iv/tests/test_medication.py raises AttributeError: '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

df = gbq.read_gbq(query, project_id=project_id, dialect="standard")
# if we find new uninspected rows, raise a warning. this will only happen when mimic-iv is updated.
if (~df['hadm_id'].contains(hadm_id_list)).any():

Root cause

pandas.Series has no .contains() method. The string accessor Series.str.contains exists 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 is Series.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 an hadm_id not already on the allow-list, which is the documented behaviour of the surrounding comment ("if we find new uninspected rows, raise a warning").

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.
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.

1 participant