You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hot: inspect fails for newliy written string variables #129
in this case sofa_test.inspect()fails, since 'test' does not have size attribute.
Not sure were to fix this, otherwise I would have opend a PR directly.
Passing it as an array is the correct/explicit way, but we allow passing data with a single dimension (such as Data_SamplingRate or the array of a single string in the example above) as a single value for convenience. So your code
should work in my opinion. In this case TestString is added to the Sofa object as a string, which causes the error in Sofa.inspect. When calling write_sofa, TestString is converted to a numpy array of strings (required for writing a sofa/NetCDF file) and after read_sofa, TestString is of type numpy.str_ and Sofa.inspect works.
I would suggest to make sure that Sofa.add_variable stores the data as a numpy.str_ to solve the problem. This would be implemented in Sofa.__setattr__ and would fix a second related bug that appears when setting the value of an existing string variable. This
Activity
f-brinkmann commentedon Oct 6, 2025
@ahms5 @mberz I updated the response. Can you check if you agree with the suggested solution.
Thanks for reporting. It works when passing the variable as array/list
['test']Passing it as an array is the correct/explicit way, but we allow passing data with a single dimension (such as
Data_SamplingRateor the array of a single string in the example above) as a single value for convenience. So your codeshould work in my opinion. In this case TestString is added to the Sofa object as a string, which causes the error in
Sofa.inspect. When callingwrite_sofa, TestString is converted to a numpy array of strings (required for writing a sofa/NetCDF file) and afterread_sofa, TestString is of type numpy.str_ andSofa.inspectworks.I would suggest to make sure that
Sofa.add_variablestores the data as a numpy.str_ to solve the problem. This would be implemented inSofa.__setattr__and would fix a second related bug that appears when setting the value of an existing string variable. Thiscauses the same error as reported above because it also calles
Sofa.__setattr__internally.