fix: prevent DataFrame mutation in prepare_data() causing indication charts to fail

prepare_data() mapped Provider Code → Name in-place. When called for directory
charts first, then indication charts, the second call re-mapped already-mapped
values to NaN, silently dropping all data. Added df.copy() to prevent mutation.

Also fixes directory charts only generating data for the first date filter.

Results: 3,633 pathway nodes now generated (1,101 directory + 2,532 indication)
across all 12 datasets (6 date filters × 2 chart types).
This commit is contained in:
Andrew Charlwood
2026-02-05 20:10:12 +00:00
parent 6f88a59978
commit 6331d44165
4 changed files with 76 additions and 10 deletions
+4
View File
@@ -53,6 +53,10 @@ def prepare_data(
if paths is None:
paths = default_paths
# Work on a copy to avoid mutating the caller's DataFrame
# (Provider Code mapping is destructive — second call would map names to NaN)
df = df.copy()
df["UPIDTreatment"] = df["UPID"] + df["Drug Name"]
org_codes = pd.read_csv(paths.org_codes_csv, index_col=1)