Skip to content

Commit b91d178

Browse files
authored
Spa.julian day microsecond fix (#942)
* Fixes microsecond scaling issue in spa.julian_day_dt, and updates the test in tests_spa to check for correct scaling
1 parent fef827b commit b91d178

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Bug fixes
4848
and various test functions.
4949
* Fix :py:func:`~pvlib.iotools.read_tmy3` so that when coerced to a single year
5050
the TMY3 index will be monotonically increasing. (:pull:`910`)
51+
* Fix :py:func:`pvlib.spa.julian_day_dt` so that microseconds are scaled
52+
correctly (:issue:`940`) (:pull:`942`)
5153

5254
Testing
5355
~~~~~~~

pvlib/spa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def julian_day_dt(year, month, day, hour, minute, second, microsecond):
430430
month = month+12
431431
a = int(year/100)
432432
b = 2 - a + int(a * 0.25)
433-
frac_of_day = (microsecond + (second + minute * 60 + hour * 3600)
433+
frac_of_day = (microsecond / 1e6 + (second + minute * 60 + hour * 3600)
434434
) * 1.0 / (3600*24)
435435
d = day + frac_of_day
436436
jd = (int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + d +

pvlib/tests/test_spa.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@
9898
class SpaBase(object):
9999
"""Test functions common to numpy and numba spa"""
100100
def test_julian_day_dt(self):
101-
dt = times.tz_convert('UTC')[0]
101+
# add 1us manually to the test timestamp (GH #940)
102+
dt = times.tz_convert('UTC')[0] + pd.Timedelta(1, unit='us')
102103
year = dt.year
103104
month = dt.month
104105
day = dt.day
105106
hour = dt.hour
106107
minute = dt.minute
107108
second = dt.second
108109
microsecond = dt.microsecond
109-
assert_almost_equal(JD,
110+
assert_almost_equal(JD + 1e-6 / (3600*24), # modify expected JD by 1us
110111
self.spa.julian_day_dt(
111112
year, month, day, hour,
112113
minute, second, microsecond), 6)

0 commit comments

Comments
 (0)