Skip to content

Commit

Permalink
add test, Changelog entry
Browse files Browse the repository at this point in the history
  • Loading branch information
jswhit committed Apr 29, 2024
1 parent 2c43046 commit ef3c46b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ since version 1.6.3 release
===========================
* build musllinux wheels (issue #307).
* return empty array if one provided to date2num (issue #315).
* handle nan/inf in num2date (issue #328).

version 1.6.3 (release tag v1.6.3rel)
=====================================
Expand Down
2 changes: 1 addition & 1 deletion src/cftime/_cftime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def num2date(
times = np.asanyarray(times) # Allow list as input
times = upcast_times(times)
# convert to masked array if any nan or inf values present
if not np.isfinite(times).any():
if not np.isfinite(times).all():
times = np.ma.masked_invalid(times)
scaled_times = scale_times(times, factor)
scaled_times = cast_to_int(scaled_times,units=unit)
Expand Down
13 changes: 13 additions & 0 deletions test/test_cftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,19 @@ def roundtrip(delta,eps,units):
# date2num should return an empty array if given one (issue #315)
d = cftime.date2num([], 'seconds since 2000-01-01 12:00:00')
assert d.size==0
# issue #328: handle nan/inf in num2date.
times = np.array([1,2,3,np.nan],dtype=np.float64)
expected = np.array([DatetimeGregorian(2000, 1, 2, 0, 0, 0, 0),
DatetimeGregorian(2000, 1, 3, 0, 0, 0, 0),
DatetimeGregorian(2000, 1, 4, 0, 0, 0, 0),
DatetimeGregorian(2000, 1, 5, 0, 0, 0, 0)])
mask = [False, False, False, True]
expected = np.ma.masked_array(expected, mask=mask)
result = cftime.num2date(times, 'days since 2000-01-01', 'standard')
np.testing.assert_equal(result, expected)
times = np.array([1,2,3,np.inf],dtype=np.float64)
result = cftime.num2date(times, 'days since 2000-01-01', 'standard')
np.testing.assert_equal(result, expected)


class TestDate2index(unittest.TestCase):
Expand Down

0 comments on commit ef3c46b

Please sign in to comment.