From e4ea279d4ebe5d1e893978b5bf9f53d5e90a6fdc Mon Sep 17 00:00:00 2001 From: Denis Nadeau Date: Mon, 20 Aug 2018 06:59:35 -0700 Subject: [PATCH] Issue246 (#267) * recreate cdms2 with libpng from conda-forge * force libpng=1.6.34 in circleci yml * fix #246 clone axis units issue * add test --- Lib/axis.py | 4 ++-- tests/test_cdms_axis_clone.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/test_cdms_axis_clone.py 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()