From f2b7f9d62c938137c071847f8d11f9f15e91610a Mon Sep 17 00:00:00 2001 From: martin-springer Date: Wed, 11 Sep 2024 17:27:03 -0400 Subject: [PATCH] fix pd fillna downcasting warning --- rdtools/analysis_chains.py | 4 +--- rdtools/availability.py | 24 ++++++++++++++++++------ rdtools/filtering.py | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/rdtools/analysis_chains.py b/rdtools/analysis_chains.py index d6d31c7b..e10dc425 100644 --- a/rdtools/analysis_chains.py +++ b/rdtools/analysis_chains.py @@ -544,9 +544,7 @@ def _call_clearsky_filter(filter_string): # note: the previous implementation using the & operator treated NaN # filter values as False, so we do the same here for consistency: - filter_components = \ - pd.DataFrame(filter_components)\ - .astype(bool).fillna(False) + filter_components = pd.DataFrame(filter_components).fillna(0).astype("bool") # apply special checks to ad_hoc_filter, as it is likely more prone to user error if self.filter_params.get("ad_hoc_filter", None) is not None: diff --git a/rdtools/availability.py b/rdtools/availability.py index d33c693e..2fa7ce51 100644 --- a/rdtools/availability.py +++ b/rdtools/availability.py @@ -278,8 +278,11 @@ def _calc_loss_subsystem(self, low_threshold, relative_sizes, .replace(False, np.nan) .multiply(subsystem_fraction) .min(axis=1) + .astype(float) + .fillna(1.0) ) # use safe value of 100% - smallest_delta.loc[smallest_delta.isnull] = 1 + print(smallest_delta) + # smallest_delta.loc[smallest_delta.isnull()] = 1 is_downtime = system_delta > (0.75 * smallest_delta) is_downtime[looks_online.all(axis=1)] = False @@ -417,7 +420,11 @@ def _calc_loss_system(self): all_times = self.power_system.index masked = looks_offline[self.power_expected > 0].reindex(all_times) # Note: in Series, (nan | True) is False, but (True | nan) is True - full_outage = masked.ffill() | masked.bfill() + ffill = masked.ffill() + ffill.loc[ffill.isnull()] = False + bfill = masked.bfill() + bfill.loc[bfill.isnull()] = False + full_outage = ffill | bfill # Find expected production and associated uncertainty for each outage diff = full_outage.astype(int).diff() starts = all_times[diff == 1].tolist() @@ -518,7 +525,7 @@ def _calc_loss_system(self): self.energy_cumulative_corrected = corrected_cumulative_energy self.loss_system = lost_power_full - def _combine_losses(self, rollup_period='M'): + def _combine_losses(self, rollup_period="ME"): """ Combine subsystem and system losses. @@ -556,9 +563,14 @@ def _combine_losses(self, rollup_period='M'): df['availability'] = 1 - df['lost_production'] / loss_plus_actual self.results = df - def run(self, low_threshold=None, relative_sizes=None, - power_system_limit=None, quantiles=(0.01, 0.99), - rollup_period='M'): + def run( + self, + low_threshold=None, + relative_sizes=None, + power_system_limit=None, + quantiles=(0.01, 0.99), + rollup_period="ME", + ): """ Run the availability analysis. diff --git a/rdtools/filtering.py b/rdtools/filtering.py index 348e0e19..e9f48abf 100644 --- a/rdtools/filtering.py +++ b/rdtools/filtering.py @@ -882,7 +882,7 @@ def xgboost_clip_filter(power_ac, mounting_type="fixed"): # Reindex with the original data index. Re-adjusts to original # data frequency. xgb_predictions = xgb_predictions.reindex(index=power_ac.index, method="ffill") - xgb_predictions = xgb_predictions.astype(bool).fillna(False) + xgb_predictions.loc[xgb_predictions.isnull()] = False # Regenerate the features with the original sampling frequency # (pre-resampling or interpolation). power_ac_df = power_ac.to_frame()