Skip to content

Commit

Permalink
Fix leading nans bug in _aggregate (#245)
Browse files Browse the repository at this point in the history
* fix and test

* changelog

* rst rendering

* rerun notebook

* mention notebook and set changelog date
  • Loading branch information
kandersolar authored Dec 4, 2020
1 parent 863e8bb commit ee9c81d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
26 changes: 13 additions & 13 deletions docs/degradation_and_soiling_example.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RdTools Change Log
==================

.. include:: changelog/v2.0.4.rst
.. include:: changelog/v2.0.3.rst
.. include:: changelog/v2.0.2.rst
.. include:: changelog/v2.0.1.rst
Expand Down
14 changes: 14 additions & 0 deletions docs/sphinx/source/changelog/v2.0.4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*************************
v2.0.4 (December 4, 2020)
*************************

Bug Fixes
---------
* Fix bug related to leading NaN values with
:py:func:`~rdtools.normalization.energy_from_power`. This fixed a small
normalization error in ``degradation_and_soiling_example.ipynb`` and
slightly changed the clear-sky degradation results (:issue:`244`, :pull:`245`)

Contributors
------------
* Kevin Anderson (:ghuser:`kanderso-nrel`)
3 changes: 3 additions & 0 deletions rdtools/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,9 @@ def _aggregate(time_series, target_frequency, max_timedelta, series_type):
max_interval_nanoseconds = max_timedelta.total_seconds() * 10.0**9

gap_mask = t_diffs > max_interval_nanoseconds
if time_series.index[0] != union_index[0]:
# mask leading NaNs
gap_mask[:time_series.index[0]] = True

time_series = time_series.reindex(union_index)
t_diffs = np.diff(time_series.index.astype('int64').values)
Expand Down
9 changes: 9 additions & 0 deletions rdtools/test/energy_from_power_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ def test_energy_from_power_single_value_with_target():
expected_result = pd.Series([100.], index=times, name='energy_Wh')
result = energy_from_power(power, target_frequency='H')
pd.testing.assert_series_equal(result, expected_result)

def test_energy_from_power_leading_nans():
# GH 244
power = pd.Series(1, pd.date_range('2019-01-01', freq='15min', periods=5))
power.iloc[:2] = np.nan
expected_result = pd.Series([np.nan, np.nan, 0.25, 0.25],
index=power.index[1:], name='energy_Wh')
result = energy_from_power(power)
pd.testing.assert_series_equal(result, expected_result)

0 comments on commit ee9c81d

Please sign in to comment.