Skip to content

Commit 106239c

Browse files
add support for unbounded integers in blob serialization
1 parent 231efe2 commit 106239c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

datajoint/blob.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ def read_sparse_array(self):
264264
raise DataJointError('datajoint-python does not yet support sparse arrays. Issue (#590)')
265265

266266
def read_int(self):
267-
return int(self.read_value('int64'))
267+
return int.from_bytes(self.read_value('int64'), byteorder='little', signed=True)
268268

269269
@staticmethod
270270
def pack_int(v):
271-
return b"\x0a" + np.array(v, dtype='int64').tobytes()
271+
return b"\x0a" + v.to_bytes((v.bit_length() + 7 + (v < 0)) // 8, byteorder='little', signed=True)
272272

273273
def read_bool(self):
274274
return bool(self.read_value('bool'))

tests/test_blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_pack():
3232
x = None
3333
assert_true(unpack(pack(x)) is None, "None did not match")
3434

35-
x = 7
35+
x = -255
3636
y = unpack(pack(x))
3737
assert_true(x == y and isinstance(y, int) and not isinstance(y, np.ndarray), "Native int did not match")
3838

0 commit comments

Comments
 (0)