diff --git a/src/pudl/output/ferc714.py b/src/pudl/output/ferc714.py index 8049536b46..7d027f413a 100644 --- a/src/pudl/output/ferc714.py +++ b/src/pudl/output/ferc714.py @@ -652,18 +652,20 @@ def summarized_demand_ferc714( demand_hourly_pa_ferc714.loc[ :, ["report_date", "respondent_id_ferc714", "demand_mwh"] ], + on=["report_date", "respondent_id_ferc714"], how="left", ) - .groupby(["report_date", "respondent_id_ferc714"]) - .agg({"demand_mwh": sum}) + .groupby(["report_date", "respondent_id_ferc714"], as_index=False)[ + ["demand_mwh"] + ] + .sum(min_count=1) .rename(columns={"demand_mwh": "demand_annual_mwh"}) - .reset_index() .merge( georeferenced_counties_ferc714.groupby( - ["report_date", "respondent_id_ferc714"] - ) - .agg({"population": sum, "area_km2": sum}) - .reset_index() + ["report_date", "respondent_id_ferc714"], as_index=False + )[["population", "area_km2"]].sum(min_count=1), + on=["report_date", "respondent_id_ferc714"], + how="left", ) .assign( population_density_km2=lambda x: x.population / x.area_km2, diff --git a/test/validate/service_territory_test.py b/test/validate/service_territory_test.py index 4dbee9a988..78aa9022cd 100644 --- a/test/validate/service_territory_test.py +++ b/test/validate/service_territory_test.py @@ -13,7 +13,7 @@ "df_name,expected_rows", [ ("summarized_demand_ferc714", 3_195), - ("fipsified_respondents_ferc714", 135_627), + ("fipsified_respondents_ferc714", 135_537), ("compiled_geometry_balancing_authority_eia861", 112_507), ("compiled_geometry_utility_eia861", 247_705), ],