CDAT / cdms

9 stars 10 forks source link

cdms.createAxis errors with cdms.createVariable object as input #228

Open durack1 opened 6 years ago

durack1 commented 6 years ago

I have just encountered a new problem with the cdms2.createAxis function as captured below:

If I use a non-cdms transient variable as an input, this works fine:

In [10]: import cdms2 as cdm
In [11]: cdm.createAxis([10.],id='height')
Out[11]: 
   id: height
   Length: 1
   First:  10.0
   Last:   10.0
   Python id:  0x7f0b601f3650

However, if I try using a cdms transient variable as the input, I get the following error. This is new in cdms2-2.12-np113py27_0 which was installed as part of the cmor331 release:

In [12]: cdm.createAxis(cdm.createVariable([10.],id='height',missing=1e20))
Traceback (most recent call last):
  File "/export/duro/anaconda2/envs/uvcdat2120/lib/python2.7/site-packages/IPython/core/formatters.py", line 699, in __call__
    printer.pretty(obj)
  File "/export/duro/anaconda2/envs/uvcdat2120/lib/python2.7/site-packages/IPython/lib/pretty.py", line 398, in pretty
    return _default_pprint(obj, self, cycle)
  File "/export/duro/anaconda2/envs/uvcdat2120/lib/python2.7/site-packages/IPython/lib/pretty.py", line 518, in _default_pprint
    _repr_pprint(obj, p, cycle)
  File "/export/duro/anaconda2/envs/uvcdat2120/lib/python2.7/site-packages/IPython/lib/pretty.py", line 709, in _repr_pprint
    output = repr(obj)
  File "/export/duro/anaconda2/envs/uvcdat2120/lib/python2.7/site-packages/cdms2/axis.py", line 685, in __str__
    return string.join(self.listall(), "\n") + "\n"
  File "/export/duro/anaconda2/envs/uvcdat2120/lib/python2.7/site-packages/cdms2/axis.py", line 1673, in listall
    result.append('   Length: ' + str(len(d)))
TypeError: object of type 'float' has no len()

The issue appears to occur in all releases dating back to 2.8.0 (so also 2.10 and 2.12)

dnadeau4 commented 6 years ago

Inconceivable!

durack1 commented 6 years ago

@dnadeau4 agreed, I too was flabbergasted at this discovery..

dnadeau4 commented 6 years ago

@durack1 my changed made everything failed on OSX, but passed on Linux. I have to revert.

durack1 commented 6 years ago

@dnadeau4 weird, I wonder why the difference on platforms

durack1 commented 5 years ago

This is still an issue on OSX CDAT 8.1/CDMS2 3.1.2:

bash-3.2$ source activate cdms2-312py2
(cdms2-312py2) bash-3.2$ python
Python 2.7.15 | packaged by conda-forge | (default, Feb 27 2019, 20:44:16) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cdms2 as cdm
Allow anonymous logging usage to help improve CDAT(you can also set the environment variable CDAT_ANONYMOUS_LOG to yes or no)? [yes]/no: no
>>> cdm.createAxis(cdm.createVariable([10.],id='height',missing=1e20))
/anaconda2/envs/cdms2-312py2/lib/python2.7/site-packages/cdms2/axis.py:826: UserWarning: genutil module not present, was not able to determine if axis is level based on units
  "genutil module not present, was not able to determine if axis is level based on units")
/anaconda2/envs/cdms2-312py2/lib/python2.7/site-packages/numpy/ma/core.py:3174: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  dout = self.data[indx]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda2/envs/cdms2-312py2/lib/python2.7/site-packages/cdms2/axis.py", line 749, in __str__
    return "\n".join(self.listall()) + "\n"
  File "/anaconda2/envs/cdms2-312py2/lib/python2.7/site-packages/cdms2/axis.py", line 1743, in listall
    result.append('   Length: ' + str(len(d)))
TypeError: object of type 'float' has no len()