Speed up filling nan heat rates with median
@@ -1993,7 +1993,7 @@ class GeneratorClusters:
self.fuel_prices = fetch_fuel_prices(self.settings)
self.atb_hr = fetch_atb_heat_rates(self.pudl_engine, self.settings)
- def fill_na_heat_rates(self, df):
+ def fill_na_heat_rates(self, s):
"""Fill null heat rate values with the median of the series. Not many null
values are expected.
@@ -2007,11 +2007,15 @@ class GeneratorClusters:
Dataframe
Same as input but with any null values replaced by the median.
"""
+ if s.isnull().any():
+ median_hr = s.median()
+ return s.fillna(median_hr)
+ else:
+ return s
+ # median_hr = df["heat_rate_mmbtu_mwh"].median()
+ # df["heat_rate_mmbtu_mwh"].fillna(median_hr, inplace=True)
- median_hr = df["heat_rate_mmbtu_mwh"].median()
- df["heat_rate_mmbtu_mwh"].fillna(median_hr, inplace=True)
-
- return df
+ # return df
def create_demand_response_gen_rows(self):
"""Create rows for demand response/management resources to include in the
@@ -2193,9 +2197,12 @@ class GeneratorClusters:
# Fill any null heat rate values for each tech
for tech in self.units_model["technology_description"]:
self.units_model.loc[
- self.units_model.technology_description == tech, :
+ self.units_model.technology_description == tech, "heat_rate_mmbtu_mwh"
] = self.fill_na_heat_rates(
- self.units_model.loc[self.units_model.technology_description == tech, :]
+ self.units_model.loc[
+ self.units_model.technology_description == tech,
+ "heat_rate_mmbtu_mwh",
+ ]
)
# assert (
# self.units_model["heat_rate_mmbtu_mwh"].isnull().any() is False
