Merge branch 'yaml-emit-numpy-scalar' into 'development'

single elements of numpy arrays are not of native type

See merge request damask/DAMASK!681
This commit is contained in:
Daniel Otto de Mentock 2022-12-08 12:03:54 +00:00
commit 8c6593985c
2 changed files with 6 additions and 3 deletions

View File

@ -43,7 +43,9 @@ class NiceDumper(SafeDumper):
return self.represent_data(data.tolist())
if isinstance(data, Rotation):
return self.represent_data(data.quaternion.tolist())
else:
if hasattr(data, 'dtype'):
return self.represent_data(data.item())
return super().represent_data(data)
def ignore_aliases(self,

View File

@ -46,7 +46,8 @@ class TestConfig:
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__()
assert Config({'A':np.ones(3,'i'), 'B':np.ones(1)[0]}).__repr__() == \
Config({'A':[1,1,1], 'B':1.0}).__repr__()
def test_abstract_is_valid(self):
with pytest.raises(NotImplementedError):