From b6dcdd2d8de309d9df7cce9e7c1d62616f53959d Mon Sep 17 00:00:00 2001 From: Kevin Anderson <57452607+kanderso-nrel@users.noreply.github.com> Date: Fri, 16 Jul 2021 09:21:51 -0600 Subject: [PATCH] Fix pandas 1.3.0 error and deprecations (#284) * fix pandas 1.3.0 error with np.float32 vs python float * Index.astype -> Index.view to suppress deprecation warnings * bump nbsphinx version (see #275) * Update changelog * typo fix * another typo... * fix pr numbers * delete stray colons * remove extra . Co-authored-by: Michael Deceglie --- docs/sphinx/source/changelog.rst | 2 +- docs/sphinx/source/changelog/pending.rst | 15 --------------- docs/sphinx/source/changelog/v2.0.6.rst | 20 ++++++++++++++++++++ rdtools/clearsky_temperature.py | 2 +- rdtools/normalization.py | 16 ++++++++-------- rdtools/test/normalization_pvwatts_test.py | 2 +- setup.py | 2 +- 7 files changed, 32 insertions(+), 27 deletions(-) delete mode 100644 docs/sphinx/source/changelog/pending.rst create mode 100644 docs/sphinx/source/changelog/v2.0.6.rst diff --git a/docs/sphinx/source/changelog.rst b/docs/sphinx/source/changelog.rst index 9489f816..b4901e23 100644 --- a/docs/sphinx/source/changelog.rst +++ b/docs/sphinx/source/changelog.rst @@ -1,7 +1,7 @@ RdTools Change Log ================== -.. include:: changelog/pending.rst +.. include:: changelog/v2.0.6.rst .. include:: changelog/v2.0.5.rst .. include:: changelog/v2.0.4.rst .. include:: changelog/v2.0.3.rst diff --git a/docs/sphinx/source/changelog/pending.rst b/docs/sphinx/source/changelog/pending.rst deleted file mode 100644 index 2ad5eb34..00000000 --- a/docs/sphinx/source/changelog/pending.rst +++ /dev/null @@ -1,15 +0,0 @@ -******* -Pending -******* - -Requirements ------------- -* Update specified versions of bleach in - ``docs/notebook_requirements.txt`` and matplotlib - in ``requirements.txt`` (:pull:`261`) - - -Contributors ------------- -* Kevin Anderson (:ghuser:`kanderso-nrel`) -* Michael Deceglie (:ghuser:`mdeceglie`) diff --git a/docs/sphinx/source/changelog/v2.0.6.rst b/docs/sphinx/source/changelog/v2.0.6.rst new file mode 100644 index 00000000..ecfc548a --- /dev/null +++ b/docs/sphinx/source/changelog/v2.0.6.rst @@ -0,0 +1,20 @@ +********************** +v2.0.6 (July 16, 2021) +********************** + +Bug Fixes +--------- +* Fix a failure of :py:func:`~rdtools.clearsky_temperature.get_clearsky_tamb` with pandas 1.3.0 (:pull:`284`) +* Change internal casting of timestamps into integers to use ``.view()`` instead of pandas deprecated ``.astype()`` method (:pull:`284`) + +Requirements +------------ +* Update specified versions of bleach in + ``docs/notebook_requirements.txt`` and matplotlib + in ``requirements.txt`` (:pull:`261`) + + +Contributors +------------ +* Kevin Anderson (:ghuser:`kanderso-nrel`) +* Michael Deceglie (:ghuser:`mdeceglie`) diff --git a/rdtools/clearsky_temperature.py b/rdtools/clearsky_temperature.py index 4472d70c..aca5ff11 100644 --- a/rdtools/clearsky_temperature.py +++ b/rdtools/clearsky_temperature.py @@ -139,7 +139,7 @@ def _get_pixel_value(data, i, j, k, radius): if len(list) == 0: return np.nan - return pd.Series(list).median() + return float(pd.Series(list).median()) def _get_temperature(hour_of_day, night_temp, day_temp, solar_noon_offset): diff --git a/rdtools/normalization.py b/rdtools/normalization.py index 73998611..dbe64b49 100644 --- a/rdtools/normalization.py +++ b/rdtools/normalization.py @@ -320,7 +320,7 @@ def _delta_index(series): # If there is no frequency information, explicitly calculate interval # sizes. Length of each interval calculated by using 'int64' to convert # to nanoseconds. - hours = pd.Series(series.index.astype('int64') / (10.0**9 * 3600.0)) + hours = pd.Series(series.index.view('int64') / (10.0**9 * 3600.0)) hours.index = series.index deltas = hours.diff() else: @@ -328,9 +328,9 @@ def _delta_index(series): # a meaningful interval for the first element of the timeseries # Length of each interval calculated by using 'int64' to convert to # nanoseconds. - deltas = (series.index - series.index.shift(-1)).astype('int64') / \ + deltas = (series.index - series.index.shift(-1)).view('int64') / \ (10.0**9 * 3600.0) - return deltas, np.mean(deltas.dropna()) + return deltas, np.mean(deltas[~np.isnan(deltas)]) delta_index = deprecated('2.0.0', removal='3.0.0')(_delta_index) @@ -467,7 +467,7 @@ def _t_step_nanoseconds(time_series): return a series of right labeled differences in the index of time_series in nanoseconds ''' - t_steps = np.diff(time_series.index.astype('int64')).astype('float') + t_steps = np.diff(time_series.index.view('int64')).astype('float') t_steps = np.insert(t_steps, 0, np.nan) t_steps = pd.Series(index=time_series.index, data=t_steps) return t_steps @@ -613,7 +613,7 @@ def _aggregate(time_series, target_frequency, max_timedelta, series_type): values = time_series.values # Identify gaps (including from nans) bigger than max_time_delta - timestamps = time_series.index.astype('int64').values + timestamps = time_series.index.view('int64') timestamps = pd.Series(timestamps, index=time_series.index) t_diffs = timestamps.diff() # Keep track of the gap size but with refilled NaNs and new @@ -628,7 +628,7 @@ def _aggregate(time_series, target_frequency, max_timedelta, series_type): gap_mask[:time_series.index[0]] = True time_series = time_series.reindex(union_index) - t_diffs = np.diff(time_series.index.astype('int64').values) + t_diffs = np.diff(time_series.index.view('int64')) t_diffs_hours = t_diffs / 10**9 / 3600.0 if series_type == 'instantaneous': # interpolate with trapz sum @@ -700,7 +700,7 @@ def _interpolate_series(time_series, target_index, max_timedelta=None, df = df.dropna() # convert to integer index and calculate the size of gaps in input - timestamps = df.index.astype('int64') + timestamps = df.index.view('int64') df['timestamp'] = timestamps df['gapsize_ns'] = df['timestamp'].diff() df.index = timestamps @@ -720,7 +720,7 @@ def _interpolate_series(time_series, target_index, max_timedelta=None, UserWarning) # put data on index that includes both original and target indicies - target_timestamps = target_index.astype('int64') + target_timestamps = pd.Index(target_index.view('int64')) union_index = df.index.append(target_timestamps) union_index = union_index.drop_duplicates(keep='first') df = df.reindex(union_index) diff --git a/rdtools/test/normalization_pvwatts_test.py b/rdtools/test/normalization_pvwatts_test.py index 263ce492..893d29a3 100644 --- a/rdtools/test/normalization_pvwatts_test.py +++ b/rdtools/test/normalization_pvwatts_test.py @@ -41,7 +41,7 @@ def setUp(self): periods=12, freq='MS') power_meas = 19.75 # power in dummy conditions - hours = (energy_index - energy_index.shift(-1)).astype('int64') / (10.0**9 * 3600.0) + hours = (energy_index - energy_index.shift(-1)).view('int64') / (10.0**9 * 3600.0) dummy_energy = hours * power_meas self.energy = pd.Series(dummy_energy, index=energy_index) diff --git a/setup.py b/setup.py index 645e5dd8..8be5333b 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ EXTRAS_REQUIRE = { 'doc': [ 'sphinx==1.8.5', - 'nbsphinx==0.6.0', + 'nbsphinx==0.8.5', 'nbsphinx-link==1.3.0', 'pandas==0.23.0', 'pvlib==0.7.1',