diff --git a/src/rred_reports/reports/schools.py b/src/rred_reports/reports/schools.py index 9e77e30f..dd6f1225 100644 --- a/src/rred_reports/reports/schools.py +++ b/src/rred_reports/reports/schools.py @@ -108,10 +108,12 @@ def filter_by_entry_and_exit(school_dataframe: pd.DataFrame, report_year: int) - """ report_start, report_end = trial_period_dates(report_year) - return school_dataframe.loc[ - ((school_dataframe["entry_date"] > report_start) & (school_dataframe["entry_date"] < report_end)) - | ((school_dataframe["exit_date"] > report_start) & (school_dataframe["exit_date"] < report_end)) - ] + return ( + school_dataframe.loc[ + ((school_dataframe["entry_date"] > report_start) & (school_dataframe["entry_date"] < report_end)) + | ((school_dataframe["exit_date"] > report_start) & (school_dataframe["exit_date"] < report_end)) + ] + ).sort_values(by=["rred_user_id", "entry_year"]) def filter_for_three_four(school_dataframe: pd.DataFrame, report_year: int) -> pd.DataFrame: @@ -128,7 +130,9 @@ def filter_for_three_four(school_dataframe: pd.DataFrame, report_year: int) -> p outcome_filtered = school_dataframe[(school_dataframe["exit_outcome"].isin(["Discontinued", "Referred to school"]))] - return outcome_filtered[(outcome_filtered["exit_date"] > report_start) & (outcome_filtered["exit_date"] < report_end)] + return (outcome_filtered[(outcome_filtered["exit_date"] > report_start) & (outcome_filtered["exit_date"] < report_end)]).sort_values( + by=["rred_user_id", "entry_year"] + ) def filter_six(school_dataframe: pd.DataFrame, report_year: int) -> pd.DataFrame: @@ -145,10 +149,12 @@ def filter_six(school_dataframe: pd.DataFrame, report_year: int) -> pd.DataFrame outcome_filtered = school_dataframe[(school_dataframe["exit_outcome"].isin(["Discontinued", "Referred to school"]))] - return outcome_filtered[ - ((outcome_filtered["month3_testdate"] > report_start) & (outcome_filtered["month3_testdate"] < report_end)) - | ((outcome_filtered["month6_testdate"] > report_start) & (outcome_filtered["month6_testdate"] < report_end)) - ] + return ( + outcome_filtered[ + ((outcome_filtered["month3_testdate"] > report_start) & (outcome_filtered["month3_testdate"] < report_end)) + | ((outcome_filtered["month6_testdate"] > report_start) & (outcome_filtered["month6_testdate"] < report_end)) + ] + ).sort_values(by=["rred_user_id", "entry_year"]) def summary_table(school_df: pd.DataFrame, report_year: int) -> pd.DataFrame: