Skip to content

Commit

Permalink
fix pd fillna downcasting warning
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-springer committed Sep 11, 2024
1 parent 8eb38c8 commit f2b7f9d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 1 addition & 3 deletions rdtools/analysis_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 18 additions & 6 deletions rdtools/availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rdtools/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f2b7f9d

Please sign in to comment.