Skip to content

Commit c76e0e5

Browse files
authored
fix incompatibility with pandas 0.19 and solar position calculations (#247)
* fix incompatibility with pandas 0.19 for unixtime calculation * update whatsnew * use np.array instead of try/except
1 parent f67ecff commit c76e0e5

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

docs/sphinx/source/whatsnew/v0.4.1.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Bug fixes
1313
* Fixed an error in the irradiance.klucher transposition model.
1414
The error was introduced in version 0.4.0. (:issue:`228`)
1515
* Update RAP forecast model variable names. (:issue:`241`)
16+
* Fix incompatibility with pandas 0.19 and solar position calculations.
17+
(:issue:`246`)
1618

1719

1820
Documentation

pvlib/solarposition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def spa_python(time, latitude, longitude,
317317
except (TypeError, ValueError):
318318
time = pd.DatetimeIndex([time, ])
319319

320-
unixtime = time.astype(np.int64)/10**9
320+
unixtime = np.array(time.astype(np.int64)/10**9)
321321

322322
spa = _spa_python_import(how)
323323

@@ -390,7 +390,7 @@ def get_sun_rise_set_transit(time, latitude, longitude, how='numpy',
390390

391391
# must convert to midnight UTC on day of interest
392392
utcday = pd.DatetimeIndex(time.date).tz_localize('UTC')
393-
unixtime = utcday.astype(np.int64)/10**9
393+
unixtime = np.array(utcday.astype(np.int64)/10**9)
394394

395395
spa = _spa_python_import(how)
396396

@@ -813,7 +813,7 @@ def nrel_earthsun_distance(time, how='numpy', delta_t=None, numthreads=4):
813813
except (TypeError, ValueError):
814814
time = pd.DatetimeIndex([time, ])
815815

816-
unixtime = time.astype(np.int64)/10**9
816+
unixtime = np.array(time.astype(np.int64)/10**9)
817817

818818
spa = _spa_python_import(how)
819819

pvlib/test/test_spa.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
times = (pd.date_range('2003-10-17 12:30:30', periods=1, freq='D')
3131
.tz_localize('MST'))
32-
unixtimes = times.tz_convert('UTC').astype(np.int64)*1.0/10**9
32+
unixtimes = np.array(times.tz_convert('UTC').astype(np.int64)*1.0/10**9)
33+
3334
lat = 39.742476
3435
lon = -105.1786
3536
elev = 1830.14
@@ -251,6 +252,9 @@ def test_transit_sunrise_sunset(self):
251252
sunset = pd.DatetimeIndex([dt.datetime(1996, 7, 5, 17, 1, 4),
252253
dt.datetime(2004, 12, 4, 19, 2, 2)]
253254
).tz_localize('UTC').astype(np.int64)*1.0/10**9
255+
times = np.array(times)
256+
sunrise = np.array(sunrise)
257+
sunset = np.array(sunset)
254258
result = self.spa.transit_sunrise_sunset(times, -35.0, 0.0, 64.0, 1)
255259
assert_almost_equal(sunrise/1e3, result[1]/1e3, 3)
256260
assert_almost_equal(sunset/1e3, result[2]/1e3, 3)
@@ -262,6 +266,9 @@ def test_transit_sunrise_sunset(self):
262266
).tz_localize('UTC').astype(np.int64)*1.0/10**9
263267
sunrise = pd.DatetimeIndex([dt.datetime(1994, 1, 2, 7, 8, 12),]
264268
).tz_localize('UTC').astype(np.int64)*1.0/10**9
269+
times = np.array(times)
270+
sunrise = np.array(sunrise)
271+
sunset = np.array(sunset)
265272
result = self.spa.transit_sunrise_sunset(times, 35.0, 0.0, 64.0, 1)
266273
assert_almost_equal(sunrise/1e3, result[1]/1e3, 3)
267274
assert_almost_equal(sunset/1e3, result[2]/1e3, 3)
@@ -283,6 +290,9 @@ def test_transit_sunrise_sunset(self):
283290
dt.datetime(2015, 8, 2, 19, 10),
284291
dt.datetime(2015, 12, 2, 16, 38),],
285292
).tz_localize('MST').astype(np.int64)*1.0/10**9
293+
times = np.array(times)
294+
sunrise = np.array(sunrise)
295+
sunset = np.array(sunset)
286296
result = self.spa.transit_sunrise_sunset(times, 39.0, -105.0, 64.0, 1)
287297
assert_almost_equal(sunrise/1e3, result[1]/1e3, 1)
288298
assert_almost_equal(sunset/1e3, result[2]/1e3, 1)
@@ -305,6 +315,9 @@ def test_transit_sunrise_sunset(self):
305315
dt.datetime(2015, 12, 2, 16, 50),],
306316
).tz_localize('Asia/Shanghai'
307317
).astype(np.int64)*1.0/10**9
318+
times = np.array(times)
319+
sunrise = np.array(sunrise)
320+
sunset = np.array(sunset)
308321
result = self.spa.transit_sunrise_sunset(times, 39.917, 116.383, 64.0,1)
309322
assert_almost_equal(sunrise/1e3, result[1]/1e3, 1)
310323
assert_almost_equal(sunset/1e3, result[2]/1e3, 1)
@@ -313,6 +326,7 @@ def test_earthsun_distance(self):
313326
times = (pd.date_range('2003-10-17 12:30:30', periods=1, freq='D')
314327
.tz_localize('MST'))
315328
unixtimes = times.tz_convert('UTC').astype(np.int64)*1.0/10**9
329+
unixtimes = np.array(unixtimes)
316330
result = self.spa.earthsun_distance(unixtimes, 64.0, 1)
317331
assert_almost_equal(R, result, 6)
318332

0 commit comments

Comments
 (0)