[python-hdf5storage] 37/84: Fixed bug where too big a number can be read into an int in Python 2.x. Gets read into a long if this is the case.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:25:01 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 0.1.10
in repository python-hdf5storage.
commit f6aca67b20c838cf96431d283af9b9763a28b549
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Tue Apr 21 01:34:08 2015 -0400
Fixed bug where too big a number can be read into an int in Python 2.x. Gets read into a long if this is the case.
---
hdf5storage/Marshallers.py | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index aec0acc..50a7c6d 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -1319,12 +1319,25 @@ class PythonScalarMarshaller(NumpyScalarArrayMarshaller):
# The type string determines how to convert it back to a Python
# type (just look up the entry in types). As it might be
# returned as an ndarray, it needs to be run through
- # np.asscalar.
+ # np.asscalar. Now, since int and long are unified in Python 3.x
+ # and the size of int in Python 2.x is not always the same, if
+ # the type_string is 'int', then we need to check to see if it
+ # can fit into an int if we are in Python 2.x. If it will fit,
+ # it is returned as an int. If it would not fit, it is returned
+ # as a long.
type_string = get_attribute_string(grp[name], 'Python.Type')
if type_string in self.python_type_strings:
tp = self.types[self.python_type_strings.index(
type_string)]
- return tp(np.asscalar(data))
+ sdata = np.asscalar(data)
+ if sys.hexversion >= 0x03000000 or tp != int:
+ return tp(sdata)
+ else:
+ num = long(sdata)
+ if num > sys.maxint or num < (-sys.maxint + 1):
+ return num
+ else:
+ return int(num)
else:
# Must be some other type, so return it as is.
return data
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-hdf5storage.git
More information about the debian-science-commits
mailing list