Skip to content

Commit a117550

Browse files
authored
Bug Fix: Pandas loc-chaining (#272)
* add updated hourly offset code * use updated offsets for pandas * fix missed offset * update matched codes * remove all soon-to-be-deprecated offsets * swap out outdated offset * update schemas for new offset usage * final swap out of offsets * finish identifying old offsets * update offsets throughout examples * convert lingering offsets * update hardcoded offsets in analysis * update hardcoded offsets in utils * fix lingering offsets in tests * update bokeh dependency * rerun and fix all but cubico example * update changelog and setup.py * update M to ME and MS * update docs examples * refactor loc-chaining in example and add missing assignment * udpate NA-dataframe deprecation warning * update results for missing NaN assignment * update changelog
1 parent c016aae commit a117550

File tree

5 files changed

+54
-50
lines changed

5 files changed

+54
-50
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ All notable changes to this project will be documented in this file. If you make
2424
`pytest test/unit` or `pytest test/regression`.
2525
- Converts some configuration files into `pyproject.toml` settings to reduce visual clutter
2626
at the top-level of the directory.
27+
- Updates chained `.loc` expressions to be a single `.loc` expression in project_ENGIE.py to silence
28+
a Pandas deprecation warning about future changes.
29+
- Adds a missing NaN assignment to `project_ENGIE.py:clean_scada`, which causes a slight change in
30+
results for the TIE and wake loss regression tests.
31+
- `openoa.utils.timeseries.gap_fill_data_frame()` now returns the original data if there is no data
32+
to fill in, avoiding a Pandas `concat` deprecation warning about pending behavioral changes.
2733

2834
## [3.0.1 - 2023-12-22]
2935

examples/project_ENGIE.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,11 @@ def clean_scada(scada_file: str | Path) -> pd.DataFrame:
9696

9797
# Cancel out readings where the wind vane direction repeats more than 3 times in a row
9898
ix_flag = filters.unresponsive_flag(scada_df.loc[ix_turbine], 3, col=["Va_avg"])
99-
scada_df.loc[ix_turbine].loc[ix_flag.values, sensor_cols]
99+
scada_df.loc[ix_flag.loc[ix_flag["Va_avg"]].index, sensor_cols] = np.nan
100100

101101
# Cancel out the temperature readings where the value repeats more than 20 times in a row
102102
ix_flag = filters.unresponsive_flag(scada_df.loc[ix_turbine], 20, col=["Ot_avg"])
103-
104-
# NOTE: ix_flag is flattened here because as a series it's shape = (N, 1) and
105-
# incompatible with this style of indexing, so we need it as shape = (N,)
106-
scada_df.loc[ix_turbine, "Ot_avg"].loc[ix_flag.values.flatten()] = np.nan
103+
scada_df.loc[ix_flag.loc[ix_flag["Ot_avg"]].index, "Ot_avg"] = np.nan
107104

108105
logger.info("Converting pitch to the range [-180, 180]")
109106
scada_df.loc[:, "Ba_avg"] = scada_df["Ba_avg"] % 360

openoa/utils/timeseries.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ def gap_fill_data_frame(data: pd.DataFrame, dt_col: str, freq: str) -> pd.DataFr
209209

210210
gap_df = pd.DataFrame(columns=data.columns)
211211
gap_df[dt_col] = find_time_gaps(data[dt_col], freq)
212-
212+
if gap_df.size == 0:
213+
return data.sort_values(dt_col)
213214
return pd.concat([data, gap_df], axis=0).sort_values(dt_col)
214215

215216

test/regression/turbine_long_term_gross_energy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ def test_longterm_gross_energy_results(self):
6666

6767
# Test UQ case, mean value
6868
res_uq = self.analysis_uq.plant_gross.mean()
69-
check_uq = 13.5355472
69+
check_uq = 13.5355463
7070
npt.assert_almost_equal(res_uq / 1e6, check_uq)
7171

7272
# Test UQ case, stdev
7373
res_std_uq = self.analysis_uq.plant_gross.std()
74-
check_std_uq = 0.12160433
74+
check_std_uq = 0.12161093
7575
npt.assert_almost_equal(res_std_uq / 1e6, check_std_uq)
7676

7777
def tearDown(self):

test/regression/wake_losses.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def check_simulation_results_wake_losses_without_UQ(self):
115115
# Make sure wake loss results are consistent to six decimal places
116116
# Confirm plant-level and turbine-level wake losses for POR and long-term corrected
117117
# wake loss estimates.
118-
expected_results_por = [0.341373, -11.731022, 10.896697, 4.066565, -1.901445]
119-
expected_results_lt = [0.366551, -9.720648, 10.275454, 2.925906, -2.043558]
118+
expected_results_por = [0.341363, -11.731031, 10.896701, 4.066524, -1.901442]
119+
expected_results_lt = [0.366556, -9.720608, 10.275471, 2.925847, -2.043537]
120120

121121
calculated_results_por = [100 * self.analysis.wake_losses_por]
122122
calculated_results_por += list(100 * np.array(self.analysis.turbine_wake_losses_por))
@@ -133,28 +133,28 @@ def check_simulation_results_wake_losses_with_UQ(self):
133133
# Confirm plant-level and turbine-level means and std. devs. from Monte Carlo simulation results
134134
# for POR and long-term corrected wake loss estimates.
135135
expected_results_por = [
136-
0.472843,
137-
1.525822,
138-
-11.556679,
139-
11.021310,
140-
4.174661,
141-
-1.781930,
142-
1.704648,
143-
1.367939,
144-
1.487695,
145-
1.557837,
136+
0.472743,
137+
1.521414,
138+
-11.563967,
139+
11.02269,
140+
4.175078,
141+
-1.776634,
142+
1.698539,
143+
1.36572,
144+
1.484835,
145+
1.551052,
146146
]
147147
expected_results_lt = [
148-
0.646298,
149-
1.368696,
150-
-9.434464,
151-
10.603648,
152-
3.129204,
153-
-1.735165,
154-
1.535812,
155-
1.321793,
156-
1.356194,
157-
1.420057,
148+
0.646731,
149+
1.374425,
150+
-9.437244,
151+
10.615733,
152+
3.114511,
153+
-1.728213,
154+
1.548299,
155+
1.325133,
156+
1.364934,
157+
1.428777,
158158
]
159159

160160
calculated_results_por = [
@@ -180,28 +180,28 @@ def check_simulation_results_wake_losses_with_UQ_new_params(self):
180180
# Confirm plant-level and turbine-level means and std. devs. from Monte Carlo simulation results
181181
# for POR and long-term corrected wake loss estimates.
182182
expected_results_por = [
183-
0.916847,
184-
2.543303,
185-
-10.936793,
186-
11.132650,
187-
5.244208,
188-
-1.772678,
189-
2.863249,
190-
2.275958,
191-
2.405864,
192-
2.637304,
183+
0.917651,
184+
2.541353,
185+
-10.941171,
186+
11.134159,
187+
5.245831,
188+
-1.768214,
189+
2.867614,
190+
2.271275,
191+
2.404548,
192+
2.631516,
193193
]
194194
expected_results_lt = [
195-
1.140988,
196-
2.420986,
197-
-8.820242,
198-
10.996425,
199-
3.488785,
200-
-1.101014,
201-
2.496057,
202-
2.331142,
203-
2.502902,
204-
2.430892,
195+
1.140835,
196+
2.426398,
197+
-8.811414,
198+
10.995446,
199+
3.487754,
200+
-1.108443,
201+
2.525045,
202+
2.318111,
203+
2.507327,
204+
2.43125,
205205
]
206206

207207
calculated_results_por = [

0 commit comments

Comments
 (0)