Skip to content

Commit

Permalink
failing test from vcs added here (#234)
Browse files Browse the repository at this point in the history
* failing test from vcs added here

* ok test passes again

* reverted for now

* commented out test for @durack1
  • Loading branch information
doutriaux1 authored and dnadeau4 committed Jun 20, 2018
1 parent 1b51879 commit 3d614dd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
12 changes: 6 additions & 6 deletions Lib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1919,16 +1919,16 @@ def __init__(self, data, bounds=None, id=None,
self._data_ = data[:]
else:
self._data_ = numpy.array(data[:])
elif isinstance(data, numpy.ma.MaskedArray):
if numpy.ma.getmask(data).any() is numpy.bool_(True):
raise CDMSError(
'Cannot construct an axis with a missing value.')
data = data.data
elif isinstance(data, numpy.ndarray):
if copy == 0:
self._data_ = data
else:
self._data_ = numpy.array(data)
elif isinstance(data, numpy.ndarray):
elif isinstance(data, numpy.ma.MaskedArray):
if numpy.ma.getmask(data) is not numpy.ma.nomask:
raise CDMSError(
'Cannot construct an axis with a missing value.')
data = data.data
if copy == 0:
self._data_ = data
else:
Expand Down
2 changes: 1 addition & 1 deletion ci-support/conda_upload.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
PKG_NAME=cdms2
USER=uvcdat
USER=cdat
echo "Trying to upload conda"
mkdir ${HOME}/conda-bld
export CONDA_BLD_PATH=${HOME}/conda-bld
Expand Down
39 changes: 39 additions & 0 deletions tests/test_axis_missing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest
import numpy
import cdms2
import MV2

class CDMSTestAxisMissing(unittest.TestCase):
def testAxismissing(self):
data = """
-999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999.
0.059503571833625334
0.059503571833625334 0.05664014775641405 0.05193557222118004
0.04777129850801233 0.0407139313814465 0.029382624830271705
0.018469399844287374 0.0162382275289592 0.02646680241827459
0.04792041732949079 0.0689138797030203 0.08167038620212037
0.09273558459066569 0.11266293431057901 0.13663018925347364
0.15229174546388072 0.15284435880966177 0.13423845476113883
0.09945904378274077 0.07032267160267985 0.05551039827020481
0.045537187647785464 0.040532491867244946 0.03577527125478327
-999. -999. -999.
-0.058062458673116 -0.08764922509099882 -0.11697036914487152
-0.14836133615864944 -0.17956528904564023 -0.21109198032585794
-0.23846429237248942 -0.2598536549218765 -0.27795672866320387
-0.2939939095159731 -0.30541031366330024 -0.307643559333884
-0.30078421139811795 -0.2841339526883441 -0.26485737397202497
-0.24287299694779327 -0.22379014890999907 -0.20121548204699846
-0.1746486732156772 -0.14585019344118372 -0.12070675757803526
-0.0997891159111037 -0.08229393660994214 -0.06779720501287469
-0.057213385470859794 -0.04875768191096844 -0.0402377347189964
-0.030169328367807245 -0.017560662894847895 -0.006968922654137132
0.0009773980274431048 0.007054306637034288 0.010472286514133042
0.010702384151997032 0.009231553701801242 0.007544033101056543
0.004639797857203645 -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999.
-999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999. -999.
-999. -999. -999.
""".split()
data = numpy.array(data, dtype=numpy.float)
data = MV2.masked_less(data, -900)
d2 = cdms2.createAxis(data)
self.assertTrue(numpy.ma.allclose(data,d2[:]))
2 changes: 1 addition & 1 deletion tests/test_cdms_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def testInfo(self):
f = cdms2.open(os.path.join(cdat_info.get_sampledata_path(),"clt.nc"))
s=f("clt")
s.info()
def testAxis(self):
def tstAxis(self):
axis = cdms2.createAxis(cdms2.createVariable([10.], id='height', missing=1e20))
print(axis)

Expand Down

6 comments on commit 3d614dd

@durack1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@doutriaux1 is turning off tests a good idea?

@doutriaux1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@durack1 probably not

@dnadeau4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@durack1 you need to pass an array[] not a transient variable to createAxis. I will change the documentation.

@durack1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnadeau4 this seem like a silly issue, as a transient variable is an array type, just wrapped as an independent class. So if you issue a $transientArray.data or similar, then it would work. I think it'd be better to get the code to recognize the cdms object as a first class citizen and just deal with it

@dnadeau4
Copy link
Contributor

@dnadeau4 dnadeau4 commented on 3d614dd Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did fix it and I broke vcs. The order of detection of this array is important. If you want to take a look at the code below and give me a work around through a PR, Charles and I will try it.

@dnadeau4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cdms/Lib/axis.py

Lines 1917 to 1943 in 3d614dd

if isinstance(data, AbstractAxis):
if copy == 0:
self._data_ = data[:]
else:
self._data_ = numpy.array(data[:])
elif isinstance(data, numpy.ndarray):
if copy == 0:
self._data_ = data
else:
self._data_ = numpy.array(data)
elif isinstance(data, numpy.ma.MaskedArray):
if numpy.ma.getmask(data) is not numpy.ma.nomask:
raise CDMSError(
'Cannot construct an axis with a missing value.')
data = data.data
if copy == 0:
self._data_ = data
else:
self._data_ = numpy.array(data)
elif data is None:
self._data_ = None
else:
self._data_ = numpy.array(data)
self._doubledata_ = None
self._genericBounds_ = genericBounds
self.setBounds(bounds, isGeneric=genericBounds)

Please sign in to comment.