Skip to content

fix error in test_get_sun_rise_set_transit #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pvlib/solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ def get_sun_rise_set_transit(time, latitude, longitude, how='numpy',
unixtime, lat, lon, delta_t, numthreads)

# arrays are in seconds since epoch format, need to conver to timestamps
transit = pd.to_datetime(transit, unit='s', utc=True).tz_convert(
transit = pd.to_datetime(transit*1e9, unit='ns', utc=True).tz_convert(
time.tz).tolist()
sunrise = pd.to_datetime(sunrise, unit='s', utc=True).tz_convert(
sunrise = pd.to_datetime(sunrise*1e9, unit='ns', utc=True).tz_convert(
time.tz).tolist()
sunset = pd.to_datetime(sunset, unit='s', utc=True).tz_convert(
sunset = pd.to_datetime(sunset*1e9, unit='ns', utc=True).tz_convert(
time.tz).tolist()

result = pd.DataFrame({'transit': transit,
Expand Down
15 changes: 15 additions & 0 deletions pvlib/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,18 @@ def incompatible_pandas_0180(test):
out = test

return out


def incompatible_pandas_0131(test):
"""
Test won't work on pandas 0.18.0 due to pandas/numpy issue with
np.round.
"""

if pd.__version__ == '0.13.1':
out = unittest.skip(
'error on pandas 0.13.1 due to pandas/numpy')(test)
else:
out = test

return out
43 changes: 30 additions & 13 deletions pvlib/test/test_solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pvlib.location import Location
from pvlib import solarposition

from . import requires_ephem
from . import requires_ephem, incompatible_pandas_0131

# setup times and locations to be tested.
times = pd.date_range(start=datetime.datetime(2014,6,24),
Expand Down Expand Up @@ -141,23 +141,31 @@ def test_spa_python_numba_physical_dst():
assert_frame_equal(this_expected, ephem_data[expected.columns])


@incompatible_pandas_0131
def test_get_sun_rise_set_transit():
south = Location(-35.0, 0.0, tz='UTC')
times = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 0),
datetime.datetime(2004, 12, 4, 0)]
).tz_localize('UTC')
sunrise = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 7, 8, 15, 471676),
datetime.datetime(2004, 12, 4, 4, 38, 57, 27416)]
sunrise = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 7, 8, 15),
datetime.datetime(2004, 12, 4, 4, 38, 57)]
).tz_localize('UTC').tolist()
sunset = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 17, 1, 4, 479889),
datetime.datetime(2004, 12, 4, 19, 2, 2, 499704)]
sunset = pd.DatetimeIndex([datetime.datetime(1996, 7, 5, 17, 1, 4),
datetime.datetime(2004, 12, 4, 19, 2, 2)]
).tz_localize('UTC').tolist()
result = solarposition.get_sun_rise_set_transit(times, south.latitude,
south.longitude,
delta_t=64.0)
frame = pd.DataFrame({'sunrise':sunrise, 'sunset':sunset}, index=times)
del result['transit']
assert_frame_equal(frame, result)
result_rounded = pd.DataFrame(index=result.index)
# need to iterate because to_datetime does not accept 2D data
# the rounding fails on pandas < 0.17
for col, data in result.iteritems():
result_rounded[col] = pd.to_datetime(
np.floor(data.values.astype(np.int64) / 1e9)*1e9, utc=True)

del result_rounded['transit']
assert_frame_equal(frame, result_rounded)


# tests from USNO
Expand All @@ -166,18 +174,27 @@ def test_get_sun_rise_set_transit():
times = pd.DatetimeIndex([datetime.datetime(2015, 1, 2),
datetime.datetime(2015, 8, 2),]
).tz_localize('MST')
sunrise = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 7, 19, 2, 225169),
datetime.datetime(2015, 8, 2, 5, 1, 26, 963145)
sunrise = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 7, 19, 2),
datetime.datetime(2015, 8, 2, 5, 1, 26)
]).tz_localize('MST').tolist()
sunset = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 16, 49, 10, 13145),
datetime.datetime(2015, 8, 2, 19, 11, 31, 816401)
sunset = pd.DatetimeIndex([datetime.datetime(2015, 1, 2, 16, 49, 10),
datetime.datetime(2015, 8, 2, 19, 11, 31)
]).tz_localize('MST').tolist()
result = solarposition.get_sun_rise_set_transit(times, golden.latitude,
golden.longitude,
delta_t=64.0)
frame = pd.DataFrame({'sunrise':sunrise, 'sunset':sunset}, index=times)
del result['transit']
assert_frame_equal(frame, result)
result_rounded = pd.DataFrame(index=result.index)
# need to iterate because to_datetime does not accept 2D data
# the rounding fails on pandas < 0.17
for col, data in result.iteritems():
result_rounded[col] = (pd.to_datetime(
np.floor(data.values.astype(np.int64) / 1e9)*1e9, utc=True)
.tz_convert('MST'))

del result_rounded['transit']
assert_frame_equal(frame, result_rounded)


@requires_ephem
def test_pyephem_physical():
Expand Down