Skip to content

Commit 2098f15

Browse files
authored
fix months and weekdays ordering (#430)
1 parent 3f988b8 commit 2098f15

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

docs/source/whatsnew/1.0.0rc1.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Enhancements
2020

2121
Bug fixes
2222
~~~~~~~~~
23+
* Fix incorrect ordering of months and weekdays in metrics plots.
24+
(:issue:`428`) (:pull:`430`)
25+
2326

2427
Contributors
2528
~~~~~~~~~~~~

solarforecastarbiter/metrics/calculator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,17 @@ def _sort_metrics_vals(metrics_vals, mapping):
253253
category_ordering = list(datamodel.ALLOWED_CATEGORIES.keys())
254254

255255
def sorter(metricval):
256+
if metricval.category == 'month':
257+
index_order = calendar.month_abbr[0:13].index(metricval.index)
258+
elif metricval.category == 'weekday':
259+
index_order = calendar.day_abbr[0:7].index(metricval.index)
260+
else:
261+
index_order = metricval.index
262+
256263
return (
257264
category_ordering.index(metricval.category),
258265
metric_ordering.index(metricval.metric),
259-
metricval.index,
266+
index_order,
260267
metricval.value
261268
)
262269

solarforecastarbiter/metrics/tests/test_calculator.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,28 @@ def test_calculate_metrics_single_uncert(single_forecast_observation_uncert,
197197
def test_calculate_deterministic_metrics_sorting(single_forecast_observation,
198198
create_processed_fxobs,
199199
create_dt_index):
200+
index = pd.DatetimeIndex(
201+
# sunday, monday, tuesday
202+
['20200531 1900Z', '20200601 2000Z', '20200602 2100Z'])
200203
inp = create_processed_fxobs(
201204
single_forecast_observation,
202-
pd.Series([2, 1, 0], index=create_dt_index(3)),
203-
pd.Series([1, 1, 1], index=create_dt_index(3)))
204-
categories = ('hour', 'total', 'date')
205+
pd.Series([2, 1, 0], index=index),
206+
pd.Series([1, 1, 1], index=index))
207+
categories = ('hour', 'total', 'date', 'month', 'weekday')
205208
metrics = ('rmse', 'ksi', 'mbe', 'mae')
206209
result = calculator.calculate_deterministic_metrics(
207210
inp, categories, metrics)
208211
expected = {
209212
0: ('total', 'mae', '0', 2/3),
210213
1: ('total', 'mbe', '0', 0.),
211-
4: ('hour', 'mae', '0', 1.),
212-
6: ('hour', 'mae', '2', 1.),
213-
10: ('hour', 'rmse', '0', 1.)
214+
4: ('month', 'mae', 'May', 1.),
215+
5: ('month', 'mae', 'Jun', 0.5),
216+
12: ('hour', 'mae', '19', 1.),
217+
14: ('hour', 'mae', '21', 1.),
218+
18: ('hour', 'rmse', '19', 1.),
219+
39: ('weekday', 'mbe', 'Mon', 0.),
220+
40: ('weekday', 'mbe', 'Tue', -1.),
221+
41: ('weekday', 'mbe', 'Sun', 1.),
214222
}
215223
attr_order = ('category', 'metric', 'index', 'value')
216224
for k, expected_attrs in expected.items():

0 commit comments

Comments
 (0)