diff --git a/sofar/sofa.py b/sofar/sofa.py index ee13fe0..de50ef1 100644 --- a/sofar/sofa.py +++ b/sofar/sofa.py @@ -149,7 +149,10 @@ def __setattr__(self, name: str, value): "only data (e.g., to repair corrupted SOFA data).")) # convert to numpy array or scalar - if not isinstance(value, (str, dict, np.ndarray)) \ + if isinstance(value, str): + if self._convention.get(name, {}).get("type") == "string": + value = np.str_(value) + elif not isinstance(value, (dict, np.ndarray)) \ and name != "protected": value = np.atleast_2d(value) if value.size == 1: diff --git a/tests/test_sofa.py b/tests/test_sofa.py index 9e9810e..108ea9e 100644 --- a/tests/test_sofa.py +++ b/tests/test_sofa.py @@ -169,6 +169,17 @@ def test_inspect(capfd): assert out == "".join(text) +def test_inspect_scalar_string_variable(capfd): + sofa = sf.Sofa("GeneralTF") + sofa.add_variable("TestString", "test", "string", "S") + sofa.inspect() + assert "TestString : test" in capfd.readouterr().out + + sofa.TestString = "updated" + sofa.inspect() + assert "TestString : updated" in capfd.readouterr().out + + def test_add_entry(): sofa = sf.Sofa("GeneralTF")