Skip to content

Inconsistent behaviour of get_units with References #1616

Open
@andrewlee94

Description

@andrewlee94

When using the get_units method on a Reference to a component with units, the output is not the same as if the get_units method was applied to the component itself. A simple example is shown below:

m = ConcreteModel()
m.var = Var([1, 2, 3, 4], units=units.m)
m.ref = Reference(m.var[:])

print(units.get_units(m.var))
>>> m

print(units.get_units(m.ref))
>>> None

Note that if applied to elements of the Reference, the result is correct (i.e. print(units.get_units(m.ref[1]) returns m).

In this case, the get_units method should probably return the correct value or raise an Exception. Otherwise, this could create confusion for users.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions