TypeError when export_structure is called
Summary
When the export_structure
function is called on a system containing a variable with None
type as its value, a TypeError
is raised.
CoSApp version = 0.12.1
Steps to reproduce
Minimal test system:
class TestSystem(System):
def setup(self):
self.add_inward('test', None)
def compute(self):
pass
ts = TestSystem('ts')
To reproduce bug:
ts_struct = ts.export_structure()
What is the expected correct behavior?
None
type should be assigned to the parameter in the output.
Possible fixes
Here is a suggestion for a fix: to include a try/catch when a None
type is present. Lines 878 onwards in cosapp/ports/variable.py
could be changed from:
for key in ["valid_range", "limits"]:
tmp_val = list(getattr(self, key))
for idx, val in enumerate(tmp_val):
if numpy.isinf(val):
tmp_val[idx] = str(val)
if tmp_val == ["-inf", "inf"]:
tmp_val = None
data[key] = tmp_val
return data
to:
for key in ["valid_range", "limits"]:
try:
tmp_val = list(getattr(self, key))
for idx, val in enumerate(tmp_val):
if numpy.isinf(val):
tmp_val[idx] = str(val)
if tmp_val == ["-inf", "inf"]:
tmp_val = None
except TypeError:
tmp_val = None
data[key] = tmp_val
return data