Skip to content

Header datatype verification inconsistent for array/non-array types #2

@spthm

Description

@spthm

Currently, e.g. ss.header.num_files must be assigned a np.int32 value. Assigning a normal Python int won't work; the type is too large and fails in the snapshot header verification at converted = np.asarray(data).view(dtype=dtype). This is inconsistent with the behaviour of array-like header elements, where this conversion will work fine, although e.g. an array of Python ints will become a twice-as-long array of np.int32 types. The to_array method does not suffer from this weirdness; converting a single Python number, or a list of Python numbers, to a single or list of `np.int32' works as desired!

So basically the verification either needs to be stricter, and balk at converting to arrays when the number of items isn't preserved, or more lax, and just check that a non-array value can be converted to the desired type, regardless of whether those types are the same size.

The former is obviously safer but a pain to use, and leads to non-obvious error messages (this could be fixed), and of dubious benefit. The more relevant danger is allowing non-array assignments to array values, and vice-versa.

Checking the conversion just as in to_array, where a size is also required, is probably the route to go.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions