Skip to content

Commit

Permalink
fixng the double call to school_aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
katiebuntic committed Sep 1, 2023
1 parent 5b9e0b6 commit fc3551e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/rred_reports/redcap/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

0 comments on commit fc3551e

Please sign in to comment.