Skip to content

Commit

Permalink
Make sure to properly handle signed and unsigned integers that cannot…
Browse files Browse the repository at this point in the history
… be stored in 64-bits.
  • Loading branch information
1313e committed Dec 17, 2020
1 parent c4b2ae6 commit fe0a879
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hickle/loaders/load_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def create_scalar_dataset(py_obj, h_group, name, **kwargs):
kwargs.pop('compression', None)

# If py_obj is an integer and cannot be stored in 64-bits, convert to str
if isinstance(py_obj, int) and (py_obj.bit_length() > 64):
if isinstance(py_obj, int) and not (-2**63 <= py_obj < 2**64):
py_obj = bytes(str(py_obj), 'ascii')

d = h_group.create_dataset(name, data=py_obj, **kwargs)
Expand Down
7 changes: 6 additions & 1 deletion hickle/tests/test_hickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,16 @@ def test_65bit_int():
""" Dumping and loading an integer with arbitrary precision
https://github.com/telegraphic/hickle/issues/113"""
i = 2**65-1
i = 2**64
dump(i, 'test.hdf5')
i_hkl = load('test.hdf5')
assert i == i_hkl

j = -2**63-1
dump(j, 'test.hdf5')
j_hkl = load('test.hdf5')
assert j == j_hkl


def test_list():
""" Dumping and loading a list """
Expand Down

0 comments on commit fe0a879

Please sign in to comment.