diff --git a/Lib/axis.py b/Lib/axis.py index b070ba54..83af3cea 100644 --- a/Lib/axis.py +++ b/Lib/axis.py @@ -1708,13 +1708,13 @@ def clone(self, copyData=1): else: mycopy = createAxis(self[:]) mycopy.id = self.id + mycopy.__dict__.update(self.__dict__.copy()) + mycopy._obj_ = None # Erase Cdfile object if exist try: mycopy.setBounds(b, isGeneric=isGeneric[0]) except CDMSError: b = mycopy.genGenericBounds() mycopy.setBounds(b, isGeneric=False) - for k, v in list(self.attributes.items()): - setattr(mycopy, k, v) return mycopy def listall(self, all=None): diff --git a/tests/test_cdms_axis_clone.py b/tests/test_cdms_axis_clone.py new file mode 100644 index 00000000..5799e198 --- /dev/null +++ b/tests/test_cdms_axis_clone.py @@ -0,0 +1,28 @@ +from __future__ import print_function +import unittest +import os +from subprocess import Popen, PIPE +import shlex +import MV2, cdms2 + + +class TestAxis(unittest.TestCase): + + def testCloneUnits(self): + + tmp = MV2.ones(3, id='tmp') + ax = tmp.getAxis(0) + ax.standard_name = "time" + ax.id = 'time' + ax.units = "seconds since 1900-01-01T00:00:00Z" + ax.long_name = "time in seconds (UT)" + ax.time_origin = "01-JAN-1900 00:00:00" + ax.designateTime() + + f = cdms2.open('tmp.nc', 'w') + f.write(tmp) + f.close() + + f = cdms2.open('tmp.nc') + assert f['time'].clone().units == f['time'].units + f.close()