[python-hdf5storage] 47/152: Fixed documentation and changed references to the aliases np.string_ and np.unicode to their targets np.bytes_ and np.str_.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:33 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 0.1
in repository python-hdf5storage.
commit 28ed1f03335420b757331f4a4582635c3c8b2c6b
Author: Freja Nordsiek <fnordsie at gmail.com>
Date: Sun Jan 26 22:51:49 2014 -0500
Fixed documentation and changed references to the aliases np.string_ and np.unicode to their targets np.bytes_ and np.str_.
---
hdf5storage/Marshallers.py | 48 ++++++++++++++++++++++++++++++----------------
hdf5storage/utilities.py | 24 +++++++++++------------
2 files changed, 43 insertions(+), 29 deletions(-)
diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index dcdcd45..0e2e3d8 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -51,6 +51,10 @@ class TypeMarshaller(object):
to be overridden and the different attributes set to the proper
values.
+ For marshalling types that are containers of other data, one will
+ need to appropriate read/write them with the lowlevel functions
+ ``lowlevel.read_data`` and ``lowlevel.write_data``.
+
Attributes
----------
cpython_attributes : set of str
@@ -70,6 +74,8 @@ class TypeMarshaller(object):
h5py.Dataset
h5py.Group
h5py.AttributeManager
+ hdf5storage.lowlevel.read_data
+ hdf5storage.lowlevel.write_data
"""
def __init__(self):
@@ -182,6 +188,10 @@ class TypeMarshaller(object):
Must be overridden in a subclass because a
``NotImplementedError`` is thrown immediately.
+ See Also
+ --------
+ hdf5storage.lowlevel.write_data
+
"""
raise NotImplementedError('Can''t write data type: '
+ str(type(data)))
@@ -280,6 +290,10 @@ class TypeMarshaller(object):
Must be overridden in a subclass because a
``NotImplementedError`` is thrown immediately.
+ See Also
+ --------
+ hdf5storage.lowlevel.read_data
+
"""
raise NotImplementedError('Can''t read data: ' + name)
@@ -293,14 +307,14 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
self.matlab_attributes |= {'MATLAB_class', 'MATLAB_empty',
'MATLAB_int_decode'}
self.types = [np.ndarray, np.matrix,
- np.bool8,
+ np.bool_,
np.uint8, np.uint16, np.uint32, np.uint64,
np.int8, np.int16, np.int32, np.int64,
np.float16, np.float32, np.float64,
np.complex64, np.complex128,
- np.string_, np.unicode]
+ np.bytes_, np.str_]
self.cpython_type_strings = ['numpy.ndarray', 'numpy.matrix',
- 'numpy.bool8',
+ 'numpy.bool_',
'numpy.uint8', 'numpy.uint16',
'numpy.uint32', 'numpy.uint64',
'numpy.int8', 'numpy.int16',
@@ -309,14 +323,14 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
'numpy.float64',
'numpy.complex64',
'numpy.complex128',
- 'numpy.string_', 'numpy.unicode']
+ 'numpy.bytes_', 'numpy.str_']
# If we are storing in MATLAB format, we will need to be able to
# set the MATLAB_class attribute. The different numpy types just
# need to be properly mapped to the right strings. Some types do
# not have a string since MATLAB does not support them.
- self.__MATLAB_classes = {np.bool8: 'logical',
+ self.__MATLAB_classes = {np.bool_: 'logical',
np.uint8: 'uint8',
np.uint16: 'uint16',
np.uint32: 'uint32',
@@ -329,13 +343,13 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
np.float64: 'double',
np.complex64: 'single',
np.complex128: 'double',
- np.string_: 'char',
- np.unicode: 'char'}
+ np.bytes_: 'char',
+ np.str_: 'char'}
# Make a dict to look up the opposite direction (given a matlab
# class, what numpy type to use.
- self.__MATLAB_classes_reverse = {'logical': np.bool8,
+ self.__MATLAB_classes_reverse = {'logical': np.bool_,
'uint8': np.uint8,
'uint16': np.uint16,
'uint32': np.uint32,
@@ -346,7 +360,7 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
'int64': np.int64,
'single': np.float32,
'double': np.float64,
- 'char': np.unicode}
+ 'char': np.str_}
# Set matlab_classes to the supported classes (the values).
@@ -364,7 +378,7 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
if options.convert_strings_to_utf16 and not (data.size == 0 \
and options.store_shape_for_empty) \
- and data.dtype.type == np.string_:
+ and data.dtype.type == np.bytes_:
data_to_store = np.uint16(np.atleast_1d( \
data_to_store).view(np.uint8))
@@ -375,7 +389,7 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
# are not always 2 bytes long in UTF-16. So, converting them to
# uint32 makes the most sense.
- if data.dtype.type == np.unicode and not (data.size == 0 \
+ if data.dtype.type == np.str_ and not (data.size == 0 \
and options.store_shape_for_empty):
data_to_store = np.atleast_1d(data_to_store).view(np.uint32)
@@ -493,10 +507,10 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
else:
set_attribute_string(grp[name], 'MATLAB_class', '')
- if tp in (np.string_, np.unicode, np.bool8):
+ if tp in (np.bytes_, np.str_, np.bool_):
set_attribute(grp[name], 'MATLAB_int_decode', np.int64(
- {np.bool8: 1, np.string_: 2,
- np.unicode: 4}[tp]))
+ {np.bool_: 1, np.bytes_: 2,
+ np.str_: 4}[tp]))
else:
del_attribute(grp[name], 'MATLAB_int_decode')
@@ -567,7 +581,7 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
# then it needs to be converted (means it was written with
# the convert_bools_to_uint8 option).
if underlying_type == 'bool8' and data.dtype.name != 'bool':
- data = np.bool8(data)
+ data = np.bool_(data)
# Convert to scalar, matrix, or ndarray depending on the
# container type.
@@ -611,7 +625,7 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
# If it is a logical, then it must be converted to
# numpy.bool8.
if matlab_class == 'logical':
- data = np.bool8(data)
+ data = np.bool_(data)
# If it is a 'char' type, the proper conversion to
# numpy.unicode needs to be done.
@@ -675,7 +689,7 @@ class PythonStringMarshaller(NumpyScalarArrayMarshaller):
def write(self, f, grp, name, data, type_string, options):
# data just needs to be converted to a numpy string.
- cdata = np.string_(data)
+ cdata = np.bytes_(data)
# Now pass it to the parent version of this function to write
# it. The proper type_string needs to be grabbed now as the
diff --git a/hdf5storage/utilities.py b/hdf5storage/utilities.py
index f1bc8eb..0d8a399 100644
--- a/hdf5storage/utilities.py
+++ b/hdf5storage/utilities.py
@@ -65,7 +65,7 @@ def decode_to_str(data):
# assuming it is in ASCII. Otherwise, data has to be returned as is.
if isinstance(data, (np.ndarray, np.uint8, np.uint16, np.uint32,
- np.string_, np.unicode)):
+ np.bytes_, np.str_)):
if data.dtype.name == 'uint8':
return data.data.tobytes().decode(encoding='ASCII')
elif data.dtype.name == 'uint16':
@@ -110,8 +110,8 @@ def decode_to_numpy_unicode(data):
numpy.str_
"""
- # Convert first to a Python str if it isn't already an np.unicode.
- if not isinstance(data, np.unicode) \
+ # Convert first to a Python str if it isn't already an np.str_.
+ if not isinstance(data, np.str_) \
and not (isinstance(data, np.ndarray) \
and data.dtype.name.startswith('str')):
data = decode_to_str(data)
@@ -119,7 +119,7 @@ def decode_to_numpy_unicode(data):
# If it is an str, then we can wrap it in unicode. Otherwise, we
# have to return it as is.
if isinstance(data, str):
- return np.unicode(data)
+ return np.str_(data)
else:
return data
@@ -150,8 +150,8 @@ def decode_to_numpy_ascii(data):
numpy.bytes_
"""
- # Convert first to a Python str if it isn't already an np.string_.
- if not isinstance(data, np.string_) \
+ # Convert first to a Python str if it isn't already an np.bytes_.
+ if not isinstance(data, np.bytes_) \
and not (isinstance(data, np.ndarray) \
and data.dtype.name.startswith('bytes')):
data = decode_to_str(data)
@@ -160,8 +160,8 @@ def decode_to_numpy_ascii(data):
# conversion to ASCII. Otherwise, we
# have to return it as is.
if isinstance(data, str):
- return np.string_(data.encode(encoding='ASCII',
- errors='replace'))
+ return np.bytes_(data.encode(encoding='ASCII',
+ errors='replace'))
else:
return data
@@ -348,9 +348,9 @@ def get_attribute_string(target, name):
return value
elif isinstance(value, bytes):
return value.decode()
- elif isinstance(value, np.unicode):
+ elif isinstance(value, np.str_):
return str(value)
- elif isinstance(value, np.string_):
+ elif isinstance(value, np.bytes_):
return value.decode()
else:
return None
@@ -398,7 +398,7 @@ def set_attribute_string(target, name, value):
that will convert to a ``numpy.bytes_``
"""
- set_attribute(target, name, np.string_(value))
+ set_attribute(target, name, np.bytes_(value))
def set_attribute_string_array(target, name, string_list):
@@ -419,7 +419,7 @@ def set_attribute_string_array(target, name, string_list):
that will convert to a ``numpy.bytes_``
"""
- target.attrs.create(name, np.string_(string_list),
+ target.attrs.create(name, np.bytes_(string_list),
dtype=h5py.special_dtype(vlen=bytes))
--
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