Skip to content

Commit 256568f

Browse files
committed
add __len__, add ellipsis to doctest
1 parent 1b1a63c commit 256568f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/pygrib/_pygrib.pyx

+4-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ cdef extern from "numpy/arrayobject.h":
104104
npy_intp PyArray_ISCONTIGUOUS(ndarray arr)
105105
npy_intp PyArray_ISALIGNED(ndarray arr)
106106

107-
cdef extern from "grib_api.h":
107+
cdef extern from "eccodes.h":
108108
ctypedef struct grib_handle
109109
ctypedef struct grib_index
110110
ctypedef struct grib_keys_iterator
@@ -193,6 +193,7 @@ def _get_grib_api_version():
193193
major = v
194194
return "%d.%d.%d" % (major,minor,revision)
195195
grib_api_version = _get_grib_api_version()
196+
eccodes_version = grib_api_version
196197
if grib_api_version < "2.19.1":
197198
msg="Warning: ecCodes 2.19.1 or higher is recommended. You are running"
198199
warnings.warn('%s %s.' % (msg,grib_api_version))
@@ -382,6 +383,8 @@ cdef class open(object):
382383
else:
383384
self.has_multi_field_msgs=False
384385
fseek(self._fd, self._offset, SEEK_SET)
386+
def __len__(self):
387+
return self.messages
385388
def __iter__(self):
386389
return self
387390
def __next__(self):

test/test.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def test():
1010
[1:Precipitation rate:kg m**-2 s**-1 (avg):regular_gg:surface:level 0:fcst time 108-120 hrs (avg):from 200402291200, 2:Surface pressure:Pa (instant):regular_gg:surface:level 0:fcst time 120 hrs:from 200402291200, 3:Maximum temperature:K (instant):regular_gg:heightAboveGround:level 2 m:fcst time 108-120 hrs:from 200402291200, 4:Minimum temperature:K (instant):regular_gg:heightAboveGround:level 2 m:fcst time 108-120 hrs:from 200402291200]
1111
>>> grbs = pygrib.open('../sampledata/flux.grb')
1212
13+
number of messages in file
14+
>>> len(grbs)
15+
4
16+
1317
acts like a file object
1418
>>> grbs.tell()
1519
0
@@ -234,8 +238,8 @@ def test():
234238
>>> str('min/max %5.2f %5.2f' % (data.min(), data.max()))
235239
'min/max 295.40 308.10'
236240
>>> grbs = pygrib.open('../sampledata/no-radius-shapeOfEarth-7.grb2')
237-
>>> for grb in grbs: print(grb)
238-
1:Total precipitation:kg m-2 (accum):lambert:surface:level 0:fcst time 15-30 mins (accum):from 201804100000
241+
>>> for grb in grbs: print(grb) # doctest:+ELLIPSIS
242+
1:Total precipitation:kg m-2 (accum):lambert:surface:level 0:fcst time 15...-30... mins (accum):from 201804100000
239243
>>> str(grb.packingType)
240244
'grid_simple'
241245
>>> grbs.close()

0 commit comments

Comments
 (0)