diff --git a/python/damask/_config.py b/python/damask/_config.py index f2ffbbbf3..24245f4bd 100644 --- a/python/damask/_config.py +++ b/python/damask/_config.py @@ -79,7 +79,11 @@ class Config(dict): NiceDumper.add_representer(np.ndarray, array_representer) - fhandle.write(yaml.dump(self,Dumper=NiceDumper,**kwargs)) + try: + fhandle.write(yaml.dump(self,Dumper=NiceDumper,**kwargs)) + except TypeError: # compatibility with old pyyaml + del kwargs['sort_keys'] + fhandle.write(yaml.dump(self,Dumper=NiceDumper,**kwargs)) @property diff --git a/python/tests/test_Config.py b/python/tests/test_Config.py index e715ad763..67c419b3e 100644 --- a/python/tests/test_Config.py +++ b/python/tests/test_Config.py @@ -1,4 +1,5 @@ import pytest +import numpy as np from damask import Config @@ -29,6 +30,8 @@ class TestConfig: f.write(config.__repr__()) assert Config.load(tmp_path/'config.yaml') == config + def test_numpy(self,tmp_path): + assert Config({'A':np.ones(3,'i')}).__repr__() == Config({'A':[1,1,1]}).__repr__() def test_abstract_is_valid(self): assert Config().is_valid is None