Skip to content

Commit

Permalink
Fix pandas 1.3.0 error and deprecations (#284)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
kandersolar and mdeceglie authored Jul 16, 2021
1 parent df5fb5a commit b6dcdd2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs/sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 0 additions & 15 deletions docs/sphinx/source/changelog/pending.rst

This file was deleted.

20 changes: 20 additions & 0 deletions docs/sphinx/source/changelog/v2.0.6.rst
Original file line number Diff line number Diff line change
@@ -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`)
2 changes: 1 addition & 1 deletion rdtools/clearsky_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions rdtools/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,17 @@ 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:
# If there is frequency information, pandas shift can be used to gain
# 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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion rdtools/test/normalization_pvwatts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit b6dcdd2

Please sign in to comment.