nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: h5py/h5py
Pull request #2562 (2025-02-24 17:51:42)

Virtual datasets with no mappings may still be virtual
At present, it's impossible to create a virtual dataset with no mappings in h5py's high-level API; this will be silently converted to a normal contiguous/compact dataset instead.

I don't think there's much practical reason to do this, but it's nice for tools building a virtual dataset of 0-N pieces for the behaviour to be consistent at 0 and 1.

Discussed in #1660, but not the main focus of that issue.


Patch:
diff --git a/h5py/_hl/vds.py b/h5py/_hl/vds.py
index d81d890d..fac9c3be 100644
--- a/h5py/_hl/vds.py
+++ b/h5py/_hl/vds.py
@@ -171,6 +171,7 @@ class VirtualLayout:
         self._filename = filename
         self._src_filenames = set()
         self.dcpl = h5p.create(h5p.DATASET_CREATE)
+        self.dcpl.set_layout(h5d.VIRTUAL)
 
     def __setitem__(self, key, source):
         sel = select(self.shape, key, dataset=None)
@@ -212,6 +213,7 @@ class VirtualLayout:
             # but we didn't know this when making the mapping. Copy the mappings
             # to a new property list, replacing the dest filename with '.'
             new_dcpl = h5p.create(h5p.DATASET_CREATE)
+            new_dcpl.set_layout(h5d.VIRTUAL)
             for i in range(self.dcpl.get_virtual_count()):
                 src_filename = self.dcpl.get_virtual_filename(i)
                 new_dcpl.set_virtual(


Test patch:
diff --git a/h5py/tests/test_vds/test_highlevel_vds.py b/h5py/tests/test_vds/test_highlevel_vds.py
index 8eef31c5..60f659ae 100644
--- a/h5py/tests/test_vds/test_highlevel_vds.py
+++ b/h5py/tests/test_vds/test_highlevel_vds.py
@@ -461,5 +461,16 @@ class VDSUnlimitedTestCase(ut.TestCase):
     def tearDown(self):
         shutil.rmtree(self.tmpdir)
 
+
+def test_no_mappings(writable_file):
+    with writable_file.build_virtual_dataset("foo", (10, 20), np.int32):
+        pass
+
+    dset = writable_file['foo']
+    assert dset.is_virtual
+    assert dset.virtual_sources() == []
+    np.testing.assert_array_equal(dset[()], np.zeros((10, 20), np.int32))
+
+
 if __name__ == "__main__":
     ut.main()
Repository: h5py/h5py
Pull request #2582 (2025-05-16 14:58:34)

Tweak `Dataset.__repr__`
Moved from #2557


Patch:
diff --git a/h5py/_hl/dataset.py b/h5py/_hl/dataset.py
index 3d685112..5604625d 100644
--- a/h5py/_hl/dataset.py
+++ b/h5py/_hl/dataset.py
@@ -1115,17 +1115,15 @@ class Dataset(HLObject):
     @with_phil
     def __repr__(self):
         if not self:
-            r = '<Closed HDF5 dataset>'
+            return "<Closed HDF5 dataset>"
+
+        if self.name is None:
+            name = "(anonymous)"
         else:
-            if self.name is None:
-                namestr = '("anonymous")'
-            else:
-                name = pp.basename(pp.normpath(self.name))
-                namestr = '"%s"' % (name if name != '' else '/')
-            r = '<HDF5 dataset %s: shape %s, type "%s">' % (
-                namestr, self.shape, self.dtype.str
-            )
-        return r
+            name = pp.basename(pp.normpath(self.name))
+            name = f'"{name}"'
+
+        return f'<HDF5 dataset {name}: shape {self.shape}, type "{self.dtype.str}">'
 
     if hasattr(h5d.DatasetID, "refresh"):
         @with_phil


Test patch:
diff --git a/h5py/tests/test_dataset.py b/h5py/tests/test_dataset.py
index 950d35c4..ad9b706a 100644
--- a/h5py/tests/test_dataset.py
+++ b/h5py/tests/test_dataset.py
@@ -49,12 +49,19 @@ class TestRepr(BaseDataset):
         Feature: repr(Dataset) behaves sensibly
     """
 
-    def test_repr_open(self):
+    def test_repr_basic(self):
+        ds = self.f.create_dataset('foo', (4,), dtype='int32')
+        assert repr(ds) == '<HDF5 dataset "foo": shape (4,), type "<i4">'
+
+    def test_repr_closed(self):
         """ repr() works on live and dead datasets """
         ds = self.f.create_dataset('foo', (4,))
-        self.assertIsInstance(repr(ds), str)
         self.f.close()
-        self.assertIsInstance(repr(ds), str)
+        assert repr(ds) == '<Closed HDF5 dataset>'
+
+    def test_repr_anonymous(self):
+        ds = self.f.create_dataset(None, (4,), dtype='int32')
+        assert repr(ds) == '<HDF5 dataset (anonymous): shape (4,), type "<i4">'
 
 
 class TestCreateShape(BaseDataset):