From fc3551e454b1f9b84aeee909115c8fc7196a6823 Mon Sep 17 00:00:00 2001 From: katiebuntic Date: Fri, 1 Sep 2023 13:36:39 +0100 Subject: [PATCH] fixng the double call to school_aliases --- src/rred_reports/redcap/main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/rred_reports/redcap/main.py b/src/rred_reports/redcap/main.py index 96ea05f..337a0ce 100644 --- a/src/rred_reports/redcap/main.py +++ b/src/rred_reports/redcap/main.py @@ -27,7 +27,7 @@ class RedcapReader: def __init__(self, school_list: Path, school_aliases: Optional[Path] = None): self._school_list = get_unique_schools(school_list) - self._school_aliases = Path("input/school_aliases/template.toml") + self._school_aliases = None if school_aliases: try: with school_aliases.open(mode="rb") as handle: @@ -62,8 +62,6 @@ def read_single_redcap_year(self, redcap_fields: ExtractInput) -> pd.DataFrame: raw_data = pd.read_csv(redcap_fields.coded_data_path, low_memory=False) labelled_data = pd.read_csv(redcap_fields.labelled_data_path, low_memory=False) processed_wide = self.preprocess_wide_data(raw_data, labelled_data) - if self._school_aliases: - processed_wide["school_id"] = processed_wide["school_id"].replace(self._school_aliases) long = self.wide_to_long(processed_wide, redcap_fields.survey_period) long_with_names = self._add_school_name_column(long) return long_with_names[masterfile_columns()].copy() @@ -279,7 +277,7 @@ def _process_calculated_columns(self, entry_year_cols: list[str], export_data: p def _add_school_name_column(self, long_df: pd.DataFrame) -> pd.DataFrame: if self._school_aliases: - long_df["school_id"] = long_df["school_id"].replace(self._school_aliases) + long_df["school_id"] = long_df["school_id"].replace(self._school_aliases, inplace=True) named_schools = long_df.merge(self._school_list, left_on="school_id", right_on="RRED School ID", how="left") named_schools.rename({"School Name": "rrcp_school"}, axis=1, inplace=True) return named_schools