Skip to content

Commit 4ba9871

Browse files
hashstatBrandon Carpenter
and
Brandon Carpenter
authored
Change deprecated use of .astype() to .view() (#1262)
* Change deprecated use of .astype() to .view() This change is made as suggested by the pandas FutureWarning to prevent those warnings. See #1261 * Merge entries in whatsnew Co-authored-by: Brandon Carpenter <[email protected]>
1 parent 1869d87 commit 4ba9871

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

docs/sphinx/source/whatsnew/v0.9.0.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ Bug fixes
179179
* Corrected an error affecting :py:func:`~pvlib.clearsky.detect_clearsky`
180180
when data time step is not one minute. Error was introduced in v0.8.1.
181181
(:issue:`1241`, :pull:`1242`)
182-
* Corrected :py:func:`~pvlib.solarposition.spa_python` to avoid a future warning. (:pull:`1256`)
182+
* Changed deprecated use of ``.astype()`` to ``.view()`` in :py:mod:`~pvlib.solarposition`.
183+
(:pull:`1256`, :issue:`1261`, :pull:`1262`)
183184

184185
Testing
185186
~~~~~~~
@@ -218,3 +219,4 @@ Contributors
218219
* Joe Ranalli (:ghuser:`jranalli`)
219220
* Chas Schweizer (:ghuser:`cpr-chas`)
220221
* Yoann Louvet (:ghuser:`YoannUniKS`)
222+
* Brandon Carpenter (:ghuser:`hashstat`)

pvlib/solarposition.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def sun_rise_set_transit_spa(times, latitude, longitude, how='numpy',
445445

446446
# must convert to midnight UTC on day of interest
447447
utcday = pd.DatetimeIndex(times.date).tz_localize('UTC')
448-
unixtime = np.array(utcday.astype(np.int64)/10**9)
448+
unixtime = np.array(utcday.view(np.int64)/10**9)
449449

450450
spa = _spa_python_import(how)
451451

@@ -1001,7 +1001,7 @@ def nrel_earthsun_distance(time, how='numpy', delta_t=67.0, numthreads=4):
10011001
except (TypeError, ValueError):
10021002
time = pd.DatetimeIndex([time, ])
10031003

1004-
unixtime = np.array(time.astype(np.int64)/10**9)
1004+
unixtime = np.array(time.view(np.int64)/10**9)
10051005

10061006
spa = _spa_python_import(how)
10071007

@@ -1381,8 +1381,8 @@ def hour_angle(times, longitude, equation_of_time):
13811381
naive_times = times.tz_localize(None) # naive but still localized
13821382
# hours - timezone = (times - normalized_times) - (naive_times - times)
13831383
hrs_minus_tzs = 1 / NS_PER_HR * (
1384-
2 * times.astype(np.int64) - times.normalize().astype(np.int64) -
1385-
naive_times.astype(np.int64))
1384+
2 * times.view(np.int64) - times.normalize().view(np.int64) -
1385+
naive_times.view(np.int64))
13861386
# ensure array return instead of a version-dependent pandas <T>Index
13871387
return np.asarray(
13881388
15. * (hrs_minus_tzs - 12.) + longitude + equation_of_time / 4.)
@@ -1392,7 +1392,7 @@ def _hour_angle_to_hours(times, hourangle, longitude, equation_of_time):
13921392
"""converts hour angles in degrees to hours as a numpy array"""
13931393
naive_times = times.tz_localize(None) # naive but still localized
13941394
tzs = 1 / NS_PER_HR * (
1395-
naive_times.astype(np.int64) - times.astype(np.int64))
1395+
naive_times.view(np.int64) - times.view(np.int64))
13961396
hours = (hourangle - longitude - equation_of_time / 4.) / 15. + 12. + tzs
13971397
return np.asarray(hours)
13981398

@@ -1406,7 +1406,7 @@ def _local_times_from_hours_since_midnight(times, hours):
14061406
# normalize local, naive times to previous midnight and add the hours until
14071407
# sunrise, sunset, and transit
14081408
return pd.DatetimeIndex(
1409-
(naive_times.normalize().astype(np.int64) +
1409+
(naive_times.normalize().view(np.int64) +
14101410
(hours * NS_PER_HR).astype(np.int64)).astype('datetime64[ns]'),
14111411
tz=tz_info)
14121412

@@ -1415,7 +1415,7 @@ def _times_to_hours_after_local_midnight(times):
14151415
"""convert local pandas datetime indices to array of hours as floats"""
14161416
times = times.tz_localize(None)
14171417
hrs = 1 / NS_PER_HR * (
1418-
times.astype(np.int64) - times.normalize().astype(np.int64))
1418+
times.view(np.int64) - times.normalize().view(np.int64))
14191419
return np.array(hrs)
14201420

14211421

0 commit comments

Comments
 (0)