Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid use of apply in computing infection status in schisto module #683

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/tlo/methods/schisto.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,18 +518,21 @@ def update_infectious_status_and_symptoms(self, idx: pd.Index) -> None:
if not len(idx) > 0:
return

def _inf_status(age: int, agg_wb: int) -> str:
if age < 5:
if agg_wb >= params['high_intensity_threshold_PSAC']:
return 'High-infection'

if agg_wb >= params['high_intensity_threshold']:
return 'High-infection'

if agg_wb >= params['low_intensity_threshold']:
return 'Low-infection'

return 'Non-infected'
def _get_infection_status(population: pd.DataFrame) -> pd.Series:
age = population["age_years"]
agg_wb = population[prop("aggregate_worm_burden")]
status = pd.Series(
"Non-infected",
index=population.index,
dtype=population[prop("infection_status")].dtype
)
high_group = (
(age < 5) & (agg_wb >= params["high_intensity_threshold_PSAC"])
) | (agg_wb >= params["high_intensity_threshold"])
low_group = ~high_group & (agg_wb >= params["low_intensity_threshold"])
status[high_group] = "High-infection"
status[low_group] = "Low-infection"
return status

def _impose_symptoms_of_high_intensity_infection(idx: pd.Index) -> None:
"""Assign symptoms to the person with high intensity infection.
Expand All @@ -547,11 +550,7 @@ def _impose_symptoms_of_high_intensity_infection(idx: pd.Index) -> None:
disease_module=schisto_module
)

correct_status = df.loc[idx].apply(
lambda x: _inf_status(x['age_years'], x[prop('aggregate_worm_burden')]),
axis=1
)

correct_status = _get_infection_status(df.loc[idx])
original_status = df.loc[idx, prop('infection_status')]

# Impose symptoms for those newly having 'High-infection' status
Expand Down