8000 fix issue converting datetimeindex to epoch int on 32 bit machines · djgagne/pvlib-python@cabcbc6 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit cabcbc6

Browse files
committed
fix issue converting datetimeindex to epoch int on 32 bit machines
1 parent c0edac4 commit cabcbc6

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ Bug fixes
2525
* fix local build of the documentation (:issue:`49`, :issue:`56`)
2626
* The release date of 0.1 was fixed in the documentation
2727
(see :ref:`whatsnew_0100`)
28+
* fix casting of DateTimeIndex to int64 epoch timestamp on machines with 32 bit python int (:issue:`63`)
2829

2930
Contributors
3031
~~~~~~~~~~~~
3132

3233
* Will Holmgren
3334
* Rob Andrews
3435
* bmu
36+
* Tony Lorenzo

pvlib/solarposition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def spa_python(time, location, pressure=101325, temperature=12, delta_t=None,
287287
except (TypeError, ValueError):
288288
time = pd.DatetimeIndex([time, ])
289289

290-
unixtime = localize_to_utc(time, location).astype(int)/10**9
290+
unixtime = localize_to_utc(time, location).astype(np.int64)/10**9
291291

292292
spa = _spa_python_import(how)
293293

@@ -363,7 +363,7 @@ def get_sun_rise_set_transit(time, location, how='numpy', delta_t=None,
363363

364364
# must convert to midnight UTC on day of interest
365365
utcday = pd.DatetimeIndex(time.date).tz_localize('UTC')
366-
unixtime = utcday.astype(int)/10**9
366+
unixtime = utcday.astype(np.int64)/10**9
367367

368368
spa = _spa_python_import(how)
369369

pvlib/spa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ def solar_position(unixtime, lat, lon, elev, pressure, temp, delta_t,
10781078
unixtime : numpy array
10791079
Array of unix/epoch timestamps to calculate solar position for.
10801080
Unixtime is the number of seconds since Jan. 1, 1970 00:00:00 UTC.
1081-
A pandas.DatetimeIndex is easily converted using .astype(int)/10**9
1081+
A pandas.DatetimeIndex is easily converted using .astype(np.int64)/10**9
10821082
lat : float
10831083
Latitude to calculate solar position for
10841084
lon : float

pvlib/test/test_spa.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
times = pd.date_range('2003-10-17 12:30:30', periods=1, freq='D').tz_localize('MST')
33-
unixtimes = times.tz_convert('UTC').astype(int)*1.0/10**9
33+
unixtimes = times.tz_convert('UTC').astype(np.int64)*1.0/10**9
3434
lat = 39.742476
3535
lon = -105.1786
3636
elev = 1830.14
@@ -246,24 +246,24 @@ def test_transit_sunrise_sunset(self):
246246
# tests at greenwich
247247
times = pd.DatetimeIndex([dt.datetime(1996, 7, 5, 0),
248248
dt.datetime(2004, 12, 4, 0)]
249-
).tz_localize('UTC').astype(int)*1.0/10**9
249+
).tz_localize('UTC').astype(np.int64)*1.0/10**9
250250
sunrise = pd.DatetimeIndex([dt.datetime(1996, 7, 5, 7, 8, 15),
251251
dt.datetime(2004, 12, 4, 4, 38, 57)]
252-
).tz_localize('UTC').astype(int)*1.0/10**9
252+
).tz_localize('UTC').astype(np.int64)*1.0/10**9
253253
sunset = pd.DatetimeIndex([dt.datetime(1996, 7, 5, 17, 1, 4),
254254
dt.datetime(2004, 12, 4, 19, 2, 2)]
255-
).tz_localize('UTC').astype(int)*1.0/10**9
255+
).tz_localize('UTC').astype(np.int64)*1.0/10**9
256256
result = self.spa.transit_sunrise_sunset(times, -35.0, 0.0, 64.0, 1)
257257
npt.assert_almost_equal(sunrise/1e3, result[1]/1e3, 3)
258258
npt.assert_almost_equal(sunset/1e3, result[2]/1e3, 3)
259259

260260

261261
times = pd.DatetimeIndex([dt.datetime(1994, 1, 2),]
262-
).tz_localize('UTC').astype(int)*1.0/10**9
262+
).tz_localize('UTC').astype(np.int64)*1.0/10**9
263263
sunset = pd.DatetimeIndex([dt.datetime(1994, 1, 2, 16, 59, 55),]
264-
).tz_localize('UTC').astype(int)*1.0/10**9
264+
).tz_localize('UTC').astype(np.int64)*1.0/10**9
265265
sunrise = pd.DatetimeIndex([dt.datetime(1994, 1, 2, 7, 8, 12),]
266-
).tz_localize('UTC').astype(int)*1.0/10**9
266+
).tz_localize('UTC').astype(np.int64)*1.0/10**9
267267
result = self.spa.transit_sunrise_sunset(times, 35.0, 0.0, 64.0, 1)
268268
npt.assert_almost_equal(sunrise/1e3, result[1]/1e3, 3)
269269
npt.assert_almost_equal(sunset/1e3, result[2]/1e3, 3)
@@ -274,17 +274,17 @@ def test_transit_sunrise_sunset(self):
274274
dt.datetime(2015, 4, 2),
275275
dt.datetime(2015, 8, 2),
276276
dt.datetime(2015, 12, 2),],
277-
).tz_localize('UTC').astype(int)*1.0/10**9
277+
).tz_localize('UTC').astype(np.int64)*1.0/10**9
278278
sunrise = pd.DatetimeIndex([dt.datetime(2015, 1, 2, 7, 19),
279279
dt.datetime(2015, 4, 2, 5, 43),
280280
dt.datetime(2015, 8, 2, 5, 1),
281281
dt.datetime(2015, 12, 2, 7, 1),],
282-
).tz_localize('MST').astype(int)*1.0/10**9
282+
).tz_localize('MST').astype(np.int64)*1.0/10**9
283283
sunset = pd.DatetimeIndex([dt.datetime(2015, 1, 2, 16, 49),
284284
dt.datetime(2015, 4, 2, 18, 24),
285285
dt.datetime(2015, 8, 2, 19, 10),
286286
dt.datetime(2015, 12, 2, 16, 38),],
287-
).tz_localize('MST').astype(int)*1.0/10**9
287+
).tz_localize('MST').astype(np.int64)*1.0/10**9
288288
result = self.spa.transit_sunrise_sunset(times, 39.0, -105.0, 64.0, 1)
289289
npt.assert_almost_equal(sunrise/1e3, result[1]/1e3, 1)
290290
npt.assert_almost_equal(sunset/1e3, result[2]/1e3, 1)
@@ -294,19 +294,19 @@ def test_transit_sunrise_sunset(self):
294294
dt.datetime(2015, 4, 2),
295295
dt.datetime(2015, 8, 2),
296296
dt.datetime(2015, 12, 2),],
297-
).tz_localize('UTC').astype(int)*1.0/10**9
297+
).tz_localize('UTC').astype(np.int64)*1.0/10**9
298298
sunrise = pd.DatetimeIndex([dt.datetime(2015, 1, 2, 7, 36),
299299
dt.datetime(2015, 4, 2, 5, 58),
300300
dt.datetime(2015, 8, 2, 5, 13),
301301
dt.datetime(2015, 12, 2, 7, 17),],
302302
).tz_localize('Asia/Shanghai'
303-
).astype(int)*1.0/10**9
303+
).astype(np.int64)*1.0/10**9
304304
sunset = pd.DatetimeIndex([dt.datetime(2015, 1, 2, 17, 0),
305305
dt.datetime(2015, 4, 2, 18, 39),
306306
dt.datetime(2015, 8, 2, 19, 28),
307307
dt.datetime(2015, 12, 2, 16, 50),],
308308
).tz_localize('Asia/Shanghai'
309-
).astype(int)*1.0/10**9
309+
).astype(np.int64)*1.0/10**9
310310
result = self.spa.transit_sunrise_sunset(times, 39.917, 116.383, 64.0,1)
311311
npt.assert_almost_equal(sunrise/1e3, result[1]/1e3, 1)
312312
npt.assert_almost_equal(sunset/1e3, result[2]/1e3, 1)

0 commit comments

Comments
 (0)
0