Skip to content

Commit 8e13d4f

Browse files
author
Dorian Birraux
committed
Add error message for invalid array type
The message is taken from NumericArray itself.
1 parent e978f25 commit 8e13d4f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

wolframclient/language/array.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from wolframclient.serializers.wxfencoder import constants
44
from wolframclient.utils.encoding import concatenate_bytes
5+
from wolframclient.exception import WolframLanguageException
56

67
try:
78
from collections.abc import Sequence
@@ -15,7 +16,10 @@ def __init__(self, array, type, shape=None):
1516
self.array = array
1617
self.shape = shape or (len(array),)
1718
self.type = type
18-
self.struct = constants.STRUCT_MAPPING[type]
19+
try:
20+
self.struct = constants.STRUCT_MAPPING[type]
21+
except KeyError:
22+
raise WolframLanguageException('Type %s is not one of the supported array types: %s.' % (type, ', '.join(constants.STRUCT_MAPPING.keys())))
1923

2024
def tobytes(self):
2125
return concatenate_bytes(self.struct.pack(el) for el in self.array)

0 commit comments

Comments
 (0)