import h5py, numpy as np
hdf = h5py.File('/tmp/1.hdf5', 'w')
v, vnp = True, np.bool_(True)
print "original types ", type(v), type(vnp)
hdf.create_dataset("1", None, None, v)
hdf.create_dataset("2", None, None, vnp)
# get it back bow
v_ = hdf.get("1")[()]
vnp_ = hdf.get("2")[()]
print "read back type ", type(v_), type(vnp_)
on 1.3.0 it returns:
original types <type 'bool'> <type 'numpy.bool_'>
read back type <type 'bool'> <type 'bool'>
and on 2.0.0:
original types <type 'bool'> <type 'numpy.bool_'>
read back type <type 'numpy.bool_'> <type 'numpy.bool_'>
so if before it would cast numpy.bool_ into generic bool (which is imho more
preferable), now basic bool type gets casted into numpy.bool_, so
that v is not v_ any more
is that intentional change?
--
=------------------------------------------------------------------=
Keep in touch www.onerussian.com
Yaroslav Halchenko www.ohloh.net/accounts/yarikoptic
> I wonder if that is intentional change introduced in 2.0.0 since in
> 1.3.0 it is all good: consider following snippet:
>
> and on 2.0.0:
>
> original types <type 'bool'> <type 'numpy.bool_'>
> read back type <type 'numpy.bool_'> <type 'numpy.bool_'>
>
> so if before it would cast numpy.bool_ into generic bool (which is imho more
> preferable), now basic bool type gets casted into numpy.bool_, so
> that v is not v_ any more
I don't think this was specifically intentional, but in general if a
NumPy type and native Python type both exist for a scalar quantity,
h5py should return the NumPy type. In this case numpy.bool_ is the
type I would have expected, if for no other reason than to make the
types obtained by slicing scalar and multidimensional datasets the
same. I think casting to native Python equivalents for bools was an
unintended side effect of some code in 1.3.1 that tried (poorly) to
support new types like variable length strings.
Andrew
On Fri, 21 Oct 2011, Andrew Collette wrote:
> I don't think this was specifically intentional, but in general if a
> NumPy type and native Python type both exist for a scalar quantity,
> h5py should return the NumPy type. In this case numpy.bool_ is the
> type I would have expected, if for no other reason than to make the
> types obtained by slicing scalar and multidimensional datasets the
> same. I think casting to native Python equivalents for bools was an
> unintended side effect of some code in 1.3.1 that tried (poorly) to
> support new types like variable length strings.
> Andrew