[python-hdf5storage] 40/84: Added code to throw exception for longs that are too big to fit into a numpy.int64.
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 a33f0dde4cd843d68ae93043da5b06f85d764427
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Sun Apr 26 01:04:26 2015 -0400
Added code to throw exception for longs that are too big to fit into a numpy.int64.
---
hdf5storage/Marshallers.py | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index 50a7c6d..c98bc04 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -1298,13 +1298,23 @@ class PythonScalarMarshaller(NumpyScalarArrayMarshaller):
self.matlab_classes = []
def write(self, f, grp, name, data, type_string, options):
- # data just needs to be converted to the appropriate numpy type
- # (pass it through np.array and then access [()] to get the
- # scalar back as a scalar numpy type) and then pass it to the
- # parent version of this function. The proper type_string needs
- # to be grabbed now as the parent function will have a modified
- # form of data to guess from if not given the right one
+ # data just needs to be converted to the appropriate numpy
+ # type. If it is a Python 3.x int or Python 2.x long that is too
+ # big to fit in a numpy.int64, we need to throw an overflow
+ # exception so it doesn't get packaged as an object. Otherwise,
+ # data is passed through np.array and then access [()] to get
+ # the scalar back as a scalar numpy type. The proper type_string
+ # needs to be grabbed now as the parent function will have a
+ # modified form of data to guess from if not given the right one
# explicitly.
+ if sys.hexversion >= 0x03000000:
+ tp = int
+ else:
+ tp = long
+ if isinstance(data, tp) \
+ and (data > 2**63 or data < -(2**63) + 1):
+ raise OverflowError('Int/long too big to fit into '
+ + 'numpy.int64.')
NumpyScalarArrayMarshaller.write(self, f, grp, name,
np.array(data)[()],
self.get_type_string(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