Skip to content

Commit 1f0cd28

Browse files
author
David Lonie
committed
Merge pull request #861 from UV-CDAT/issue_757_averager_0d_issue
Issue 757 averager 0d issue
2 parents bf352fd + bc9a6ab commit 1f0cd28

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

Packages/cdms2/Lib/MV2.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,12 @@ def average (a, axis=None, weights=None, returned=False):
402402
ta = _makeMaskedArg(a)
403403
maresult = numpy.ma.average(ta, axis, weights, returned)
404404
axes, attributes, id, grid = _extractMetadata(a, omit=axis, omitall=(axis is None))
405-
if returned: maresult, wresult = maresult
405+
if returned:
406+
if isinstance(maresult,tuple):
407+
maresult, wresult = maresult
408+
else:
409+
#ok it's masked constant need to return both things by hand
410+
wresult = numpy.ma.masked
406411
F=getattr(a,"fill_value",1.e20)
407412
r1 = TransientVariable(maresult, axes=axes, attributes=attributes, grid=grid, id=id,no_update_from=True, fill_value=F)
408413
if returned:

testing/cdms2/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ add_test("CDMS_asdatetime"
112112
${CMAKE_INSTALL_PREFIX}/bin/python
113113
${cdat_SOURCE_DIR}/testing/cdms2/test_cdms2_axis_as_datetime.py)
114114

115+
add_test("test_cdms2_full_averagering_full_missing"
116+
${CMAKE_INSTALL_PREFIX}/bin/python
117+
${cdat_SOURCE_DIR}/testing/cdms2/test_full_averaging.py
118+
)
119+
115120
# Tests which should fail
116121
# set_tests_properties(testSo2TasACCESSFails PROPERTIES PASS_REGULAR_EXPRESSION "FAILED")
117122

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import cdutil,MV2
2+
import cdms2,numpy
3+
4+
cdms2.setAutoBounds("on")
5+
6+
7+
a = MV2.masked_greater(MV2.array([1,4,5,6,7,8,9.]),.5)
8+
9+
assert numpy.ma.is_masked(cdutil.averager(a))

0 commit comments

Comments
 (0)