Skip to content

TransformerConstant is only supposed to handle np.number datatypes, but is used by Constant for union[int, float, str]. #374

@jmtoepperwien

Description

@jmtoepperwien

The implementation of TransformerConstant.to_value uses np.full_like to return an array filled with the corresponding values. The dtype is given via type(self.value), but when Constant represents a str value, numpy uses U1 (unicode string of length 1) as the default datatype (at least for numpy version 1.26.3), truncating the value as a consequence.

The main problem here is, that the Transformer class is defined as only being able to handle np.number datatypes, but Constant uses it for all values anyways. A quick and dirty fix is to use 'U100' for np.full_like whenever the actual type is str, but this disregards the mismatch in the type hints.

As I've found this problem during debugging a given template, I don't have a minimal code example prepared, that exhibits this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions