[h5py] 386/455: Allow anonymous dataset creation

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:53 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 71f48d83962d312759c521907bf380448b5dbd82
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Mon Feb 8 00:03:27 2010 +0000

    Allow anonymous dataset creation
---
 h5py/defs.pxd              |  6 ++++++
 h5py/h5d.pyx               | 41 ++++++++++++++++++++++++++++++++---------
 h5py/tests/low/test_h5d.py | 20 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/h5py/defs.pxd b/h5py/defs.pxd
index 54efe93..9d8df5e 100644
--- a/h5py/defs.pxd
+++ b/h5py/defs.pxd
@@ -190,6 +190,12 @@ cdef extern from "hdf5.h":
                         H5D_operator_t operator, void* operator_data) except *
   herr_t    H5Dset_extent(hid_t dset_id, hsize_t* size)
 
+  IF H5PY_18API:
+    hid_t H5Dcreate2(hid_t loc_id, char *name, hid_t type_id, hid_t space_id,
+                     hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id) except *
+    hid_t H5Dcreate_anon(hid_t file_id, hid_t type_id, hid_t space_id,
+                     hid_t plist_id, hid_t dapl_id) except *
+
 
 # === H5F - File API ==========================================================
 
diff --git a/h5py/h5d.pyx b/h5py/h5d.pyx
index 24988af..861f6a1 100644
--- a/h5py/h5d.pyx
+++ b/h5py/h5d.pyx
@@ -56,17 +56,40 @@ FILL_VALUE_USER_DEFINED = H5D_FILL_VALUE_USER_DEFINED
 
 # === Dataset operations ======================================================
 
+IF H5PY_18API:
 
-def create(ObjectID loc not None, char* name, TypeID tid not None, 
-            SpaceID space not None, PropID dcpl=None):
-    """ (ObjectID loc, STRING name, TypeID tid, SpaceID space,
-         PropDCID dcpl=None ) 
-        => DatasetID
+    def create(ObjectID loc not None, object name, TypeID tid not None,
+               SpaceID space not None, PropID dcpl=None, PropID lcpl=None):
+        """ (objectID loc, [STRING name,], TypeID tid, SpaceID space,
+             PropDCID dcpl=None, PropID lcpl=None) => DatasetID
 
-        Create a new dataset under an HDF5 file or group.  Keyword dcpl
-        may be a dataset creation property list.
-    """
-    return DatasetID(H5Dcreate(loc.id, name, tid.id, space.id, pdefault(dcpl)))
+        Create a new dataset.  If "name" is None, the dataset will be
+        anonymous.
+        """
+        cdef hid_t dsid
+        cdef char* cname = NULL
+        if name is not None:
+            cname = name
+
+        if cname != NULL:
+            dsid = H5Dcreate2(loc.id, cname, tid.id, space.id,
+                     pdefault(lcpl), pdefault(dcpl), H5P_DEFAULT)
+        else:
+            dsid = H5Dcreate_anon(loc.id, tid.id, space.id,
+                     pdefault(dcpl), H5P_DEFAULT)
+        return DatasetID(dsid)
+
+ELSE:             
+    def create(ObjectID loc not None, char* name, TypeID tid not None, 
+                SpaceID space not None, PropID dcpl=None):
+        """ (ObjectID loc, STRING name, TypeID tid, SpaceID space,
+             PropDCID dcpl=None ) 
+            => DatasetID
+
+            Create a new dataset under an HDF5 file or group.  Keyword dcpl
+            may be a dataset creation property list.
+        """
+        return DatasetID(H5Dcreate(loc.id, name, tid.id, space.id, pdefault(dcpl)))
 
 
 def open(ObjectID loc not None, char* name):
diff --git a/h5py/tests/low/test_h5d.py b/h5py/tests/low/test_h5d.py
new file mode 100644
index 0000000..80e31c8
--- /dev/null
+++ b/h5py/tests/low/test_h5d.py
@@ -0,0 +1,20 @@
+from h5py import tests
+from h5py import *
+
+class TestCreate(tests.HTest):
+
+    def setUp(self):
+        self.fid, self.name = tests.gettemp()
+
+    def tearDown(self):
+        import os
+        self.fid.close()
+        os.unlink(self.name)
+
+    @tests.require(api=18)
+    def test_create_anon(self):
+        """ (H5D) Anonymous dataset creation """
+        sid = h5s.create_simple((10,10))
+        dsid = h5d.create(self.fid, None, h5t.STD_I32LE, sid)
+        self.assert_(dsid)
+        self.assertIsInstance(dsid, h5d.DatasetID)

-- 
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