Skip to content

Hot: inspect fails for newliy written string variables #129

In review

Description

@ahms5

inspect fails for newliy written string variables

    sofa_test = sf.Sofa('GeneralTF')
    sofa_test.add_variable('TestString', 'test', 'string', 'S')
    sofa_test.inspect()

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.

and this would work:

    sofa_test = sf.Sofa('GeneralTF')
    sofa_test.add_variable('TestString', 'test', 'string', 'S')
    sf.write_sofa(sofa_test, 'test.sofa')
    sofa_test = sf.read_sofa('test.sofa')
    sofa_test.inspect()

Activity

  1. added theissue type on Oct 3, 2025
  2. f-brinkmann commented on Oct 6, 2025

    @f-brinkmann
    Member

    @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']

    sofa_test = sf.Sofa('GeneralTF')
    sofa_test.add_variable('TestString', ['test'], 'string', 'S')
    sofa_test.inspect()

    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

    sofa_test.add_variable('TestString', 'test', 'string', 'S')

    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

    sofa = sf.Sofa('AnnotatedReceiverAudio')
    sofa.Response = 'Yes'
    sofa.inspect()

    causes the same error as reported above because it also calles Sofa.__setattr__ internally.

  3. added this to the v1.2.3 milestone on Feb 3, 2026
  4. modified the milestones: v1.2.3, v1.4.0 on Aug 27, 2026
  5. moved this from Backlog to Implementation in progress in Weekly Planningon Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions