Skip to content

ValueError: Cannot cast DatetimeIndex to dtype int32 #63

@JamieTaylor-TUOS

Description

@JamieTaylor-TUOS

In windows, receive an error using index.astype in solarposition.py line 284:

from datetime import datetime
t = datetime(2014,1,1,12,0,0)
import pandas as pd
panda_t = pd.to_datetime([t,])
import pvlib
loc = pvlib.location.Location(53, -1.5, tz='UTC')
print pvlib.solarposition.get_solarposition(panda_t, loc)
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ph1jt\Anaconda\lib\site-packages\pvlib\solarposition.py", line 79, in get_solarposition
how='numpy', kwargs)
File "C:\Users\ph1jt\Anaconda\lib\site-packages\pvlib\solarposition.py", line 284, in spa_python
unixtime = localize_to_utc(time, location).astype(int)/10
9
File "C:\Users\ph1jt\Anaconda\lib\site-packages\pandas\tseries\index.py", line 713, in astype
raise ValueError('Cannot cast DatetimeIndex to dtype %s' % dtype)
ValueError: Cannot cast DatetimeIndex to dtype int32

Changing line 284 in solarposition from:

    unixtime = localize_to_utc(time, location).astype(int)/10**9

to:

    unixtime = localize_to_utc(time, location).astype('int64')/10**9

fixes the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions