Skip to content

Commit b748856

Browse files
committed
Add second case where we have to reduce int64 to int32
We do this to allow datatype=int to be specified as an argument.
1 parent 3cdbfdd commit b748856

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

softioc/builder.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ def _waveform(value, fields):
149149
if 'datatype' in fields:
150150
assert 'FTVL' not in fields, \
151151
'Can\'t specify FTVL and datatype together'
152-
datatype = numpy.dtype(fields.pop('datatype'))
152+
datatype = fields.pop('datatype')
153+
if datatype == int or datatype == 'int':
154+
# Convert Python int to 32-bit integer, it's all we can handle
155+
datatype = numpy.dtype('int32')
156+
else:
157+
datatype = numpy.dtype(datatype)
153158
elif 'FTVL' in fields:
154159
datatype = numpy.dtype(DbfStringToNumpy[fields['FTVL']])
155160
else:
@@ -163,7 +168,7 @@ def _waveform(value, fields):
163168
length = fields.pop('length', len(initial_value))
164169

165170
# Special case for [u]int64: if the initial value comes in as 64 bit
166-
# integers cannot represent that, so recast it as [u]int32
171+
# integers we cannot represent that, so recast it as [u]int32
167172
if datatype is None:
168173
if initial_value.dtype == numpy.int64:
169174
initial_value = numpy.require(initial_value, numpy.int32)

0 commit comments

Comments
 (0)