Skip to content

Commit b05bca8

Browse files
committed
[Fix] better deal with empty struct (must have shape [0])
1 parent 5f12c5c commit b05bca8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

mpython/core/base_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def from_any(cls, other, **kwargs):
5151
return None
5252

5353
elif type__ == "emptystruct":
54-
return Struct([])
54+
return Struct.from_shape([0])
5555

5656
elif type__ == "structarray":
5757
# MPython returns a list of dictionaries in data__

mpython/struct.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ def _as_runtime(self) -> dict:
115115
data = MatlabType._to_runtime(data)
116116
return data
117117

118+
if np.ndarray.view(self, np.ndarray).size == 0:
119+
return dict(type__="emptystruct")
120+
118121
size = np.array([[*np.shape(self)]])
119122
data = np.ndarray.view(self, np.ndarray)
120123
data = np.reshape(data, [-1], order="F")

0 commit comments

Comments
 (0)