diff --git a/hickle/loaders/load_builtins.py b/hickle/loaders/load_builtins.py index d9c21b03..a4e438ad 100644 --- a/hickle/loaders/load_builtins.py +++ b/hickle/loaders/load_builtins.py @@ -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) diff --git a/hickle/tests/test_hickle.py b/hickle/tests/test_hickle.py index 5ecfb3db..695091ed 100644 --- a/hickle/tests/test_hickle.py +++ b/hickle/tests/test_hickle.py @@ -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 """