Skip to content

Commit c61fc00

Browse files
committed
fix for issue 215
1 parent dffa80f commit c61fc00

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Changelog

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
since version 1.0.8
22
===================
3+
4+
* fix for date2index error when time variable has only one entry (issue 215).
5+
36
* silence warnings ("Non-trivial type declarators in shared declaration (e.g.
47
mix of pointers and values). Each pointer declaration should be on its own
58
line") with Cython 0.2.

netcdftime.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,12 @@ def time2index(times, nctime, calendar=None, select='exact'):
11011101

11021102
# Trying to infer the correct index from the starting time and the stride.
11031103
# This assumes that the times are increasing uniformly.
1104-
t0, t1 = nctime[:2]
1105-
dt = t1 - t0
1104+
if len(nctime) >= 2:
1105+
t0, t1 = nctime[:2]
1106+
dt = t1 - t0
1107+
else:
1108+
t0 = nctime[0]
1109+
dt = 1.
11061110
if select in ['exact', 'before']:
11071111
index = numpy.array((num-t0)/dt, int)
11081112
elif select == 'after':

0 commit comments

Comments
 (0)