Skip to content

Commit ee9c81d

Browse files
authored
Fix leading nans bug in _aggregate (#245)
* fix and test * changelog * rst rendering * rerun notebook * mention notebook and set changelog date
1 parent 863e8bb commit ee9c81d

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

docs/degradation_and_soiling_example.ipynb

Lines changed: 13 additions & 13 deletions
Large diffs are not rendered by default.

docs/sphinx/source/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
RdTools Change Log
22
==================
33

4+
.. include:: changelog/v2.0.4.rst
45
.. include:: changelog/v2.0.3.rst
56
.. include:: changelog/v2.0.2.rst
67
.. include:: changelog/v2.0.1.rst
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*************************
2+
v2.0.4 (December 4, 2020)
3+
*************************
4+
5+
Bug Fixes
6+
---------
7+
* Fix bug related to leading NaN values with
8+
:py:func:`~rdtools.normalization.energy_from_power`. This fixed a small
9+
normalization error in ``degradation_and_soiling_example.ipynb`` and
10+
slightly changed the clear-sky degradation results (:issue:`244`, :pull:`245`)
11+
12+
Contributors
13+
------------
14+
* Kevin Anderson (:ghuser:`kanderso-nrel`)

rdtools/normalization.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ def _aggregate(time_series, target_frequency, max_timedelta, series_type):
620620
max_interval_nanoseconds = max_timedelta.total_seconds() * 10.0**9
621621

622622
gap_mask = t_diffs > max_interval_nanoseconds
623+
if time_series.index[0] != union_index[0]:
624+
# mask leading NaNs
625+
gap_mask[:time_series.index[0]] = True
623626

624627
time_series = time_series.reindex(union_index)
625628
t_diffs = np.diff(time_series.index.astype('int64').values)

rdtools/test/energy_from_power_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,12 @@ def test_energy_from_power_single_value_with_target():
9999
expected_result = pd.Series([100.], index=times, name='energy_Wh')
100100
result = energy_from_power(power, target_frequency='H')
101101
pd.testing.assert_series_equal(result, expected_result)
102+
103+
def test_energy_from_power_leading_nans():
104+
# GH 244
105+
power = pd.Series(1, pd.date_range('2019-01-01', freq='15min', periods=5))
106+
power.iloc[:2] = np.nan
107+
expected_result = pd.Series([np.nan, np.nan, 0.25, 0.25],
108+
index=power.index[1:], name='energy_Wh')
109+
result = energy_from_power(power)
110+
pd.testing.assert_series_equal(result, expected_result)

0 commit comments

Comments
 (0)