[h5py] 77/455: Fixes and improvements
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:19 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.
commit e541f06703b2f92a4ce2b15b8522aa3b2155081f
Author: andrewcollette <andrew.collette at gmail.com>
Date: Thu Jul 17 21:20:20 2008 +0000
Fixes and improvements
---
README.txt | 4 ++--
h5py/h5d.pyx | 51 +++++++++++++++++++++---------------------
h5py/h5f.pyx | 26 +++++++++-------------
h5py/h5fd.pxd | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
h5py/h5fd.pyx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
h5py/h5p.pxd | 13 +++++++++++
h5py/h5p.pyx | 29 ++++++++++++++++++++++++
h5py/highlevel.py | 52 ++++++++++++++++++++-----------------------
h5py/numpy.pxd | 5 +++++
h5py/tests/common.py | 2 +-
h5py/tests/test_h5d.py | 2 +-
h5py/tests/test_h5t.py | 2 +-
h5py/utils.pyx | 8 +++----
setup.py | 2 +-
14 files changed, 236 insertions(+), 79 deletions(-)
diff --git a/README.txt b/README.txt
index 752bac5..1b492ae 100644
--- a/README.txt
+++ b/README.txt
@@ -126,8 +126,8 @@ Additional options
--pyrex-force Recompile all pyx files, regardless of timestamps.
--no-pyrex Don't run Pyrex, no matter what
- --hdf5=path Use alternate HDF5 directory (contains bin, include, lib)
- --api=<n> Specifies API version. Only --api=16 is currently allowed.
+ --hdf5=path Use alternate HDF5 directory (containing bin, include, lib)
+ --api=<n> Specifies API version. Only --api=16 is currently useful.
--debug=<n> If nonzero, compile in debug mode. The number is
interpreted as a logging-module level number. Requires
Pyrex for recompilation.
diff --git a/h5py/h5d.pyx b/h5py/h5d.pyx
index 5112ec3..9d0eb8a 100644
--- a/h5py/h5d.pyx
+++ b/h5py/h5d.pyx
@@ -23,6 +23,7 @@ from utils cimport check_numpy_read, check_numpy_write, \
require_tuple, \
convert_tuple, \
emalloc, efree
+from h5 cimport HADDR_UNDEF
# Runtime imports
import h5
@@ -57,17 +58,15 @@ FILL_VALUE_USER_DEFINED = H5D_FILL_VALUE_USER_DEFINED
# === Basic dataset operations ================================================
def create(ObjectID loc not None, char* name, TypeID tid not None,
- SpaceID space not None, PropDCID plist=None):
+ SpaceID space not None, PropDCID dcpl=None):
""" (ObjectID loc, STRING name, TypeID tid, SpaceID space,
- PropDCID plist=None )
+ PropDCID dcpl=None )
=> DatasetID
- Create a new dataset under an HDF5 file or group. Keyword plist
+ Create a new dataset under an HDF5 file or group. Keyword dcpl
may be a dataset creation property list.
"""
- cdef hid_t plist_id
- plist_id = pdefault(plist)
- return DatasetID(H5Dcreate(loc.id, name, tid.id, space.id, plist_id))
+ return DatasetID(H5Dcreate(loc.id, name, tid.id, space.id, pdefault(dcpl)))
def open(ObjectID loc not None, char* name):
""" (ObjectID loc, STRING name) => DatasetID
@@ -96,9 +95,9 @@ cdef class DatasetID(ObjectID):
"""
property dtype:
- """ Numpy-style dtype object representing the dataset type """
+ """ Numpy dtype object representing the dataset type """
def __get__(self):
- # Dataset type can't change
+ # Dataset type can't change
cdef TypeID tid
if self._dtype is None:
tid = self.get_type()
@@ -106,7 +105,7 @@ cdef class DatasetID(ObjectID):
return self._dtype
property shape:
- """ Numpy-stype shape tuple representing the dataspace """
+ """ Numpy-style shape tuple representing the dataspace """
def __get__(self):
# Shape can change (DatasetID.extend), so don't cache it
cdef SpaceID sid
@@ -130,13 +129,13 @@ cdef class DatasetID(ObjectID):
H5Dclose(self.id)
def read(self, SpaceID mspace not None, SpaceID fspace not None,
- ndarray arr_obj not None, PropDXID plist=None):
+ ndarray arr_obj not None, PropDXID dxpl=None):
""" (SpaceID mspace, SpaceID fspace, NDARRAY arr_obj,
- PropDXID plist=None)
+ PropDXID dxpl=None)
Read data from an HDF5 dataset into a Numpy array. For maximum
flexibility, you can specify dataspaces for the file and the Numpy
- object. Keyword plist may be a dataset transfer property list.
+ object. Keyword dxpl may be a dataset transfer property list.
The provided Numpy array must be writable, C-contiguous, and own
its data. If this is not the case, ValueError will be raised and
@@ -149,21 +148,19 @@ cdef class DatasetID(ObjectID):
large a dataspace.
"""
cdef TypeID mtype
- cdef hid_t plist_id
- plist_id = pdefault(plist)
mtype = h5t.py_create(arr_obj.dtype)
check_numpy_write(arr_obj, -1)
- H5Dread(self.id, mtype.id, mspace.id, fspace.id, plist_id, PyArray_DATA(arr_obj))
+ H5Dread(self.id, mtype.id, mspace.id, fspace.id, pdefault(dxpl), PyArray_DATA(arr_obj))
def write(self, SpaceID mspace not None, SpaceID fspace not None,
- ndarray arr_obj not None, PropDXID plist=None):
+ ndarray arr_obj not None, PropDXID dxpl=None):
""" (SpaceID mspace, SpaceID fspace, NDARRAY arr_obj,
- PropDXID plist=None)
+ PropDXID dxpl=None)
- Write data from a Numpy array to an HDF5 dataset. Keyword plist may
+ Write data from a Numpy array to an HDF5 dataset. Keyword dxpl may
be a dataset transfer property list.
The provided Numpy array must be C-contiguous, and own its data.
@@ -171,13 +168,11 @@ cdef class DatasetID(ObjectID):
will fail.
"""
cdef TypeID mtype
- cdef hid_t plist_id
- plist_id = pdefault(plist)
mtype = h5t.py_create(arr_obj.dtype)
check_numpy_read(arr_obj, -1)
- H5Dwrite(self.id, mtype.id, mspace.id, fspace.id, plist_id, PyArray_DATA(arr_obj))
+ H5Dwrite(self.id, mtype.id, mspace.id, fspace.id, pdefault(dxpl), PyArray_DATA(arr_obj))
def extend(self, object shape):
""" (TUPLE shape)
@@ -243,12 +238,18 @@ cdef class DatasetID(ObjectID):
return propwrap(H5Dget_create_plist(self.id))
def get_offset(self):
- """ () => LONG offset
+ """ () => LONG offset or None
- Get the offset of this dataset in the file, in bytes, or -1 if
- it can't be determined.
+ Get the offset of this dataset in the file, in bytes, or None if
+ it doesn't have one. This is always the case for datasets which
+ use chunked storage, compact datasets, and datasets for which space
+ has not yet been allocated in the file.
"""
- return H5Dget_offset(self.id)
+ cdef haddr_t offset
+ offset = H5Dget_offset(self.id)
+ if offset == HADDR_UNDEF:
+ return None
+ return offset
def get_storage_size(self):
""" () => LONG storage_size
diff --git a/h5py/h5f.pyx b/h5py/h5f.pyx
index 2f23611..e65ff41 100644
--- a/h5py/h5f.pyx
+++ b/h5py/h5f.pyx
@@ -52,21 +52,19 @@ OBJ_LOCAL = H5F_OBJ_LOCAL
# === File operations =========================================================
-def open(char* name, unsigned int flags=H5F_ACC_RDWR, PropFAID accesslist=None):
- """ (STRING name, UINT flags=ACC_RDWR, PropFAID accesslist=None)
+def open(char* name, unsigned int flags=H5F_ACC_RDWR, PropFAID fapl=None):
+ """ (STRING name, UINT flags=ACC_RDWR, PropFAID fapl=None)
=> FileID
Open an existing HDF5 file. Keyword "flags" may be ACC_RWDR or
- ACC_RDONLY. Accesslist may be a file access property list.
+ ACC_RDONLY. Keyword fapl may be a file access property list.
"""
- cdef hid_t plist_id
- plist_id = pdefault(accesslist)
- return FileID(H5Fopen(name, flags, plist_id))
-
-def create(char* name, int flags=H5F_ACC_TRUNC, PropFCID createlist=None,
- PropFAID accesslist=None):
- """ (STRING name, INT flags=ACC_TRUNC, PropFCID createlist=None,
- PropFAID accesslist=None)
+ return FileID(H5Fopen(name, flags, pdefault(fapl)))
+
+def create(char* name, int flags=H5F_ACC_TRUNC, PropFCID fcpl=None,
+ PropFAID fapl=None):
+ """ (STRING name, INT flags=ACC_TRUNC, PropFCID fcpl=None,
+ PropFAID fapl=None)
=> FileID
Create a new HDF5 file. Keyword "flags" may be either:
@@ -76,11 +74,7 @@ def create(char* name, int flags=H5F_ACC_TRUNC, PropFCID createlist=None,
To keep the behavior in line with that of Python's built-in functions,
the default is ACC_TRUNC. Be careful!
"""
- cdef hid_t create_id
- cdef hid_t access_id
- create_id = pdefault(createlist)
- access_id = pdefault(accesslist)
- return FileID(H5Fcreate(name, flags, create_id, access_id))
+ return FileID(H5Fcreate(name, flags, pdefault(fcpl), pdefault(fapl)))
def flush(ObjectID obj not None, int scope=H5F_SCOPE_LOCAL):
""" (ObjectID obj, INT scope=SCOPE_LOCAL)
diff --git a/h5py/h5fd.pxd b/h5py/h5fd.pxd
new file mode 100644
index 0000000..1accb19
--- /dev/null
+++ b/h5py/h5fd.pxd
@@ -0,0 +1,60 @@
+#+
+#
+# This file is part of h5py, a low-level Python interface to the HDF5 library.
+#
+# Copyright (C) 2008 Andrew Collette
+# http://h5py.alfven.org
+# License: BSD (See LICENSE.txt for full license)
+#
+# $Date$
+#
+#-
+
+# This file contains code or comments from the HDF5 library. See the file
+# licenses/hdf5.txt for the full HDF5 software license.
+
+cdef extern from "hdf5.h":
+
+ ctypedef enum H5FD_mem_t:
+ H5FD_MEM_NOLIST = -1,
+ H5FD_MEM_DEFAULT = 0,
+ H5FD_MEM_SUPER = 1,
+ H5FD_MEM_BTREE = 2,
+ H5FD_MEM_DRAW = 3,
+ H5FD_MEM_GHEAP = 4,
+ H5FD_MEM_LHEAP = 5,
+ H5FD_MEM_OHDR = 6,
+ H5FD_MEM_NTYPES
+
+
+ int H5FD_LOG_LOC_READ # 0x0001
+ int H5FD_LOG_LOC_WRITE # 0x0002
+ int H5FD_LOG_LOC_SEEK # 0x0004
+ int H5FD_LOG_LOC_IO # (H5FD_LOG_LOC_READ|H5FD_LOG_LOC_WRITE|H5FD_LOG_LOC_SEEK)
+
+ # /* Flags for tracking number of times each byte is read/written */
+ int H5FD_LOG_FILE_READ # 0x0008
+ int H5FD_LOG_FILE_WRITE # 0x0010
+ int H5FD_LOG_FILE_IO # (H5FD_LOG_FILE_READ|H5FD_LOG_FILE_WRITE)
+
+ # /* Flag for tracking "flavor" (type) of information stored at each byte */
+ int H5FD_LOG_FLAVOR # 0x0020
+
+ # /* Flags for tracking total number of reads/writes/seeks */
+ int H5FD_LOG_NUM_READ # 0x0040
+ int H5FD_LOG_NUM_WRITE # 0x0080
+ int H5FD_LOG_NUM_SEEK # 0x0100
+ int H5FD_LOG_NUM_IO # (H5FD_LOG_NUM_READ|H5FD_LOG_NUM_WRITE|H5FD_LOG_NUM_SEEK)
+
+ # /* Flags for tracking time spent in open/read/write/seek/close */
+ int H5FD_LOG_TIME_OPEN # 0x0200 # /* Not implemented yet */
+ int H5FD_LOG_TIME_READ # 0x0400 # /* Not implemented yet */
+ int H5FD_LOG_TIME_WRITE # 0x0800 # /* Partially implemented (need to track total time) */
+ int H5FD_LOG_TIME_SEEK # 0x1000 # /* Partially implemented (need to track total time & track time for seeks during reading) */
+ int H5FD_LOG_TIME_CLOSE # 0x2000 # /* Fully implemented */
+ int H5FD_LOG_TIME_IO # (H5FD_LOG_TIME_OPEN|H5FD_LOG_TIME_READ|H5FD_LOG_TIME_WRITE|H5FD_LOG_TIME_SEEK|H5FD_LOG_TIME_CLOSE)
+
+ # /* Flag for tracking allocation of space in file */
+ int H5FD_LOG_ALLOC # 0x4000
+ int H5FD_LOG_ALL # (H5FD_LOG_ALLOC|H5FD_LOG_TIME_IO|H5FD_LOG_NUM_IO|H5FD_LOG_FLAVOR|H5FD_LOG_FILE_IO|H5FD_LOG_LOC_IO)
+
diff --git a/h5py/h5fd.pyx b/h5py/h5fd.pyx
new file mode 100644
index 0000000..bd5420d
--- /dev/null
+++ b/h5py/h5fd.pyx
@@ -0,0 +1,59 @@
+#+
+#
+# This file is part of h5py, a low-level Python interface to the HDF5 library.
+#
+# Copyright (C) 2008 Andrew Collette
+# http://h5py.alfven.org
+# License: BSD (See LICENSE.txt for full license)
+#
+# $Date$
+#
+#-
+
+# This file contains code or comments from the HDF5 library. See the file
+# licenses/hdf5.txt for the full HDF5 software license.
+
+# === Multi-file driver =======================================================
+
+MEM_DEFAULT = H5FD_MEM_DEFAULT
+MEM_SUPER = H5FD_MEM_SUPER
+MEM_BTREE = H5FD_MEM_BTREE
+MEM_DRAW = H5FD_MEM_DRAW
+MEM_GHEAP = H5FD_MEM_GHEAP
+MEM_LHEAP = H5FD_MEM_LHEAP
+MEM_OHDR = H5FD_MEM_OHDR
+MEM_NTYPES = H5FD_MEM_NTYPES
+
+# === Logging driver ==========================================================
+
+LOG_LOC_READ = H5FD_LOG_LOC_READ # 0x0001
+LOG_LOC_WRITE = H5FD_LOG_LOC_WRITE # 0x0002
+LOG_LOC_SEEK = H5FD_LOG_LOC_SEEK # 0x0004
+LOG_LOC_IO = H5FD_LOG_LOC_IO # (H5FD_LOG_LOC_READ|H5FD_LOG_LOC_WRITE|H5FD_LOG_LOC_SEEK)
+
+# /* Flags for tracking number of times each byte is read/written */
+LOG_FILE_READ = H5FD_LOG_FILE_READ # 0x0008
+LOG_FILE_WRITE= H5FD_LOG_FILE_WRITE # 0x0010
+LOG_FILE_IO = H5FD_LOG_FILE_IO # (H5FD_LOG_FILE_READ|H5FD_LOG_FILE_WRITE)
+
+# /* Flag for tracking "flavor" (type) of information stored at each byte */
+LOG_FLAVOR = H5FD_LOG_FLAVOR # 0x0020
+
+# /* Flags for tracking total number of reads/writes/seeks */
+LOG_NUM_READ = H5FD_LOG_NUM_READ # 0x0040
+LOG_NUM_WRITE = H5FD_LOG_NUM_WRITE # 0x0080
+LOG_NUM_SEEK = H5FD_LOG_NUM_SEEK # 0x0100
+LOG_NUM_IO = H5FD_LOG_NUM_IO # (H5FD_LOG_NUM_READ|H5FD_LOG_NUM_WRITE|H5FD_LOG_NUM_SEEK)
+
+# /* Flags for tracking time spent in open/read/write/seek/close */
+LOG_TIME_OPEN = H5FD_LOG_TIME_OPEN # 0x0200 # /* Not implemented yet */
+LOG_TIME_READ = H5FD_LOG_TIME_READ # 0x0400 # /* Not implemented yet */
+LOG_TIME_WRITE= H5FD_LOG_TIME_WRITE # 0x0800 # /* Partially implemented (need to track total time) */
+LOG_TIME_SEEK = H5FD_LOG_TIME_SEEK # 0x1000 # /* Partially implemented (need to track total time & track time for seeks during reading) */
+LOG_TIME_CLOSE= H5FD_LOG_TIME_CLOSE # 0x2000 # /* Fully implemented */
+LOG_TIME_IO = H5FD_LOG_TIME_IO # (H5FD_LOG_TIME_OPEN|H5FD_LOG_TIME_READ|H5FD_LOG_TIME_WRITE|H5FD_LOG_TIME_SEEK|H5FD_LOG_TIME_CLOSE)
+
+# /* Flag for tracking allocation of space in file */
+LOG_ALLOC = H5FD_LOG_ALLOC # 0x4000
+LOG_ALL = H5FD_LOG_ALL # (H5FD_LOG_ALLOC|H5FD_LOG_TIME_IO|H5FD_LOG_NUM_IO|H5FD_LOG_FLAVOR|H5FD_LOG_FILE_IO|H5FD_LOG_LOC_IO)
+
diff --git a/h5py/h5p.pxd b/h5py/h5p.pxd
index f85526c..14e9330 100644
--- a/h5py/h5p.pxd
+++ b/h5py/h5p.pxd
@@ -103,6 +103,17 @@ cdef extern from "hdf5.h":
H5F_CLOSE_STRONG = 2,
H5F_CLOSE_DEFAULT = 3
+ ctypedef enum H5FD_mem_t:
+ H5FD_MEM_NOLIST = -1,
+ H5FD_MEM_DEFAULT = 0,
+ H5FD_MEM_SUPER = 1,
+ H5FD_MEM_BTREE = 2,
+ H5FD_MEM_DRAW = 3,
+ H5FD_MEM_GHEAP = 4,
+ H5FD_MEM_LHEAP = 5,
+ H5FD_MEM_OHDR = 6,
+ H5FD_MEM_NTYPES
+
# Property list classes
hid_t H5P_NO_CLASS
hid_t H5P_FILE_CREATE
@@ -141,6 +152,8 @@ cdef extern from "hdf5.h":
herr_t H5Pset_family_offset ( hid_t fapl_id, hsize_t offset) except *
herr_t H5Pget_family_offset ( hid_t fapl_id, hsize_t *offset) except *
herr_t H5Pset_fapl_log(hid_t fapl_id, char *logfile, unsigned int flags, size_t buf_size) except *
+ herr_t H5Pset_fapl_multi(hid_t fapl_id, H5FD_mem_t *memb_map, hid_t *memb_fapl,
+ char **memb_name, haddr_t *memb_addr, hbool_t relax)
# Dataset creation properties
herr_t H5Pset_layout(hid_t plist, int layout) except *
diff --git a/h5py/h5p.pyx b/h5py/h5p.pyx
index 846f741..99c3487 100644
--- a/h5py/h5p.pyx
+++ b/h5py/h5p.pyx
@@ -459,6 +459,29 @@ cdef class PropDCID(PropInstanceID):
"""
H5Premove_filter(self.id, <H5Z_filter_t>filter_class)
+ def set_fill_time(self, int fill_code):
+ """ (INT fill_code)
+
+ Set the fill time. Legal values are:
+ h5d.FILL_TIME_ALLOC
+ h5d.FILL_TIME_NEVER
+ h5d.FILL_TIME_IFSET
+ """
+ H5Pset_fill_time(self.id, fill_time)
+
+ def fill_value_defined(self):
+ """ () => INT fill_status
+
+ Determine the status of the dataset fill value. Return values are:
+ h5d.FILL_VALUE_UNDEFINED
+ h5d.FILL_VALUE_DEFAULT
+ h5d.FILL_VALUE_USER_DEFINED
+ """
+ cdef H5D_fill_value_t val
+ H5Pfill_value_defined(self.id, &val)
+ return <int>val
+
+
# === File access =============================================================
cdef class PropFAID(PropInstanceID):
@@ -549,7 +572,13 @@ cdef class PropFAID(PropInstanceID):
return (msize, plist)
+ def set_fapl_log(self, char* logfile, unsigned int flags, size_t buf_size):
+ """ (STRING logfile, UINT flags, UINT buf_size)
+ Enable the use of the logging driver. See the HDF5 documentation
+ for details. Flag constants are stored in module h5fd.
+ """
+ H5Pset_fapl_log(self.id, logfile, flags, buf_size)
diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index 1690937..33c20ea 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -38,8 +38,8 @@
Each highlevel object carries an identifier object (obj.id), which can be
used by h5py.h5* functions or methods.
- It is safe to import this module using "from h5py.highlevel import *", but
- bear in mind the function "open" will shadow the builtin "open" if you do.
+ It is safe to import this module using "from h5py.highlevel import *"; it
+ will export only the major classes.
"""
import os
@@ -52,7 +52,7 @@ from utils_hl import slicer, hbasename, strhdr, strlist
from browse import _H5Browser
__all__ = ["HLObject", "File", "Group", "Dataset",
- "Datatype", "AttributeManager", "open"]
+ "Datatype", "AttributeManager"]
try:
# For interactive File.browse() capability
@@ -60,21 +60,6 @@ try:
except ImportError:
readline = None
-def open(filename, mode='r'):
- """ Open a file. Supports the following modes:
-
- r Read-only, file must exist
- w Create, truncating if already exists
- w- Create, failing if already exists
- a Open r/w, creating if necessary; don't truncate
- r+ Read-write, file must exist
-
- The returned file object supports the Python 2.5 "with" statement.
- It will close itself at the end of a "with" block, regardless of
- exceptions raised.
- """
- return File(filename, mode)
-
class HLObject(object):
"""
@@ -266,7 +251,7 @@ class File(Group):
File(name, mode='r', noclobber=False)
Created with standard Python syntax File(name, mode).
- Legal modes: r, r+, w, a (default 'r')
+ Legal modes: r, r+, w, w-, a (default 'r')
File objects inherit from Group objects; Group-like methods all
operate on the HDF5 root group ('/'). Like Python file objects, you
@@ -276,6 +261,15 @@ class File(Group):
to browse the file and import objects into the interactive Python
session. If the readline module is available, this includes things
like command history and tab completion.
+
+ This object supports the Python context manager protocol, when used
+ in a "with" block:
+ with File(...) as f:
+ ... do stuff with f...
+ # end block
+
+ The file will be closed at the end of the block, regardless of any
+ exceptions raised.
"""
name = property(lambda self: self._name,
@@ -298,13 +292,13 @@ class File(Group):
plist = h5p.create(h5p.FILE_ACCESS)
plist.set_fclose_degree(h5f.CLOSE_STRONG)
if mode == 'r':
- self.fid = h5f.open(name, h5f.ACC_RDONLY, accesslist=plist)
+ self.fid = h5f.open(name, h5f.ACC_RDONLY, fapl=plist)
elif mode == 'r+' or mode == 'a':
- self.fid = h5f.open(name, h5f.ACC_RDWR, accesslist=plist)
+ self.fid = h5f.open(name, h5f.ACC_RDWR, fapl=plist)
elif mode == 'w-':
- self.fid = h5f.create(name, h5f.ACC_EXCL, accesslist=plist)
+ self.fid = h5f.create(name, h5f.ACC_EXCL, fapl=plist)
elif mode == 'w':
- self.fid = h5f.create(name, h5f.ACC_TRUNC, accesslist=plist)
+ self.fid = h5f.create(name, h5f.ACC_TRUNC, fapl=plist)
else:
raise ValueError("Invalid mode; must be one of r, r+, w, w-, a")
@@ -531,26 +525,28 @@ class Dataset(HLObject):
return arr[names[0]]
return arr
- def __setitem__(self, args):
+ def __setitem__(self, args, val):
""" Write to the HDF5 dataset from an Numpy array. The shape of the
Numpy array must match the shape of the selection, and the Numpy
array's datatype must be convertible to the HDF5 datatype.
"""
- val = args[-1]
- args = args[0:-1]
start, count, stride, names = slicer(self.shape, args)
if len(names) != 0:
raise ValueError("Field name selections are not allowed for write.")
if count != val.shape:
- raise ValueError("Selection shape (%s) must match target shape (%s)" % (str(count), str(val.shape)))
+ # Allow assignments (1,10) => (10,)
+ if numpy.product(count) != numpy.product(val.shape):
+ raise ValueError("Selection shape (%s) must match target shape (%s)" % (str(count), str(val.shape)))
+ else:
+ val = val.reshape(count)
fspace = self.id.get_space()
fspace.select_hyperslab(start, count, stride)
mspace = h5s.create_simple(val.shape)
- self.id.write(mspace, fspace, array(val))
+ self.id.write(mspace, fspace, numpy.array(val))
def __str__(self):
if self.id._valid:
diff --git a/h5py/numpy.pxd b/h5py/numpy.pxd
index 92fefd3..481d27f 100644
--- a/h5py/numpy.pxd
+++ b/h5py/numpy.pxd
@@ -61,6 +61,9 @@ cdef extern from "numpy/arrayobject.h":
NPY_UINT8, NPY_UINT16, NPY_UINT32, NPY_UINT64,
NPY_FLOAT32, NPY_FLOAT64, NPY_COMPLEX64, NPY_COMPLEX128
+ cdef enum:
+ NPY_WRITEABLE, NPY_ALIGNED, NPY_C_CONTIGUOUS
+
# Classes
ctypedef extern class numpy.dtype [object PyArray_Descr]:
cdef int type_num, elsize, alignment
@@ -85,6 +88,8 @@ cdef extern from "numpy/arrayobject.h":
double imag
# Functions
+ object PyArray_FROM_OF(object arr, int requirements)
+
object PyArray_GETITEM(object arr, void *itemptr)
int PyArray_SETITEM(object arr, void *itemptr, object obj)
dtype PyArray_DescrFromType(int type)
diff --git a/h5py/tests/common.py b/h5py/tests/common.py
index 8aafcab..ee34398 100644
--- a/h5py/tests/common.py
+++ b/h5py/tests/common.py
@@ -39,7 +39,7 @@ class TestBase(unittest.TestCase):
plist = h5p.create(h5p.FILE_ACCESS)
plist.set_fclose_degree(h5f.CLOSE_STRONG)
- self.fid = h5f.open(newname, h5f.ACC_RDWR, accesslist=plist)
+ self.fid = h5f.open(newname, h5f.ACC_RDWR, fapl=plist)
self.fname = newname
def tearDown(self):
diff --git a/h5py/tests/test_h5d.py b/h5py/tests/test_h5d.py
index 54c977f..86fcf06 100644
--- a/h5py/tests/test_h5d.py
+++ b/h5py/tests/test_h5d.py
@@ -97,7 +97,7 @@ class TestH5D(TestBase):
root = h5g.open(self.fid, '/')
space = h5s.create_simple((10,20),(15,20))
htype = h5t.STD_I32LE
- dset = h5d.create(root, 'NewDataset', htype, space, plist=plist)
+ dset = h5d.create(root, 'NewDataset', htype, space, dcpl=plist)
self.assertEqual(dset.shape, (10,20))
dset.extend((15,20))
self.assertEqual(dset.shape, (15,20))
diff --git a/h5py/tests/test_h5t.py b/h5py/tests/test_h5t.py
index 784e1ae..29c82e1 100644
--- a/h5py/tests/test_h5t.py
+++ b/h5py/tests/test_h5t.py
@@ -50,7 +50,7 @@ class TestH5T(unittest.TestCase):
plist = h5p.create(h5p.FILE_ACCESS)
plist.set_fclose_degree(h5f.CLOSE_STRONG)
fname = tempfile.mktemp('.hdf5')
- fid = h5f.create(fname, h5f.ACC_TRUNC, accesslist=plist)
+ fid = h5f.create(fname, h5f.ACC_TRUNC, fapl=plist)
try:
root = h5g.open(fid, '/')
htype = h5t.STD_I32LE.copy()
diff --git a/h5py/utils.pyx b/h5py/utils.pyx
index 02a54a1..9b98380 100644
--- a/h5py/utils.pyx
+++ b/h5py/utils.pyx
@@ -10,7 +10,9 @@
#
#-
-from python cimport PyTuple_Check, PyList_Check, PyErr_SetString
+from python cimport PyTuple_Check, PyList_Check, PyErr_SetString, Py_INCREF
+from numpy cimport ndarray, NPY_WRITEABLE, NPY_ALIGNED, \
+ NPY_C_CONTIGUOUS, PyArray_FROM_OF
cdef int require_tuple(object tpl, int none_allowed, int size, char* name) except -1:
# Ensure that tpl is in fact a tuple, or None if none_allowed is nonzero.
@@ -36,7 +38,7 @@ cdef int require_list(object lst, int none_allowed, int size, char* name) except
# Counterpart of require_tuple, for lists
if (lst is None and none_allowed) or \
- ( PyList_Check(lst) and (size < 0 or len(lst) == size)):
+ (PyList_Check(lst) and (size < 0 or len(lst) == size)):
return 1
nmsg = ""
@@ -59,5 +61,3 @@ cdef object pybool(long long val):
-
-
diff --git a/setup.py b/setup.py
index b89f5c5..fb512f8 100644
--- a/setup.py
+++ b/setup.py
@@ -156,7 +156,7 @@ except ImportError:
# Pyrex extension modules
pyx_modules = ['h5' , 'h5f', 'h5g', 'h5s', 'h5t', 'h5d',
- 'h5a', 'h5p', 'h5z', 'h5i', 'h5r', 'utils']
+ 'h5a', 'h5p', 'h5z', 'h5i', 'h5r', 'h5fd', 'utils']
pyx_src_path = 'h5py'
pyx_extra_src = ['utils_low.c'] # C source files required for Pyrex code
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git
More information about the debian-science-commits
mailing list