From da3489df9426c038e88c4613be509e0ddb6e77ea Mon Sep 17 00:00:00 2001
From: Guillaume Clivaz <guillaume.clivaz@idiap.ch>
Date: Wed, 21 Dec 2022 13:34:43 +0100
Subject: [PATCH] Bugfixes: gettings timestamps attributes, numpy.float
 deprectated and some bugs due to legacy bob.io.base.HDF5File code

---
 bob/io/stream/stream.py            | 4 ++--
 bob/io/stream/stream_file.py       | 6 +++---
 bob/io/stream/test/test_streams.py | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/bob/io/stream/stream.py b/bob/io/stream/stream.py
index f25e666..9bf050e 100644
--- a/bob/io/stream/stream.py
+++ b/bob/io/stream/stream.py
@@ -757,12 +757,12 @@ class StreamView(StreamFilter):
             raise ValueError(
                 str(view_indices)
                 + " in stream with shape "
-                + str(parent.shape)
+                + str(self.parent.shape)
                 + " results in empty stream. (shape "
                 + str(self.shape)
                 + ")"
             )
-            
+
         # If slice operates on more dimension than available.
         if self.bulk_view is not None and self.parent.ndim <= len(self.bulk_view):
             raise ValueError(
diff --git a/bob/io/stream/stream_file.py b/bob/io/stream/stream_file.py
index 253d99f..3282187 100644
--- a/bob/io/stream/stream_file.py
+++ b/bob/io/stream/stream_file.py
@@ -130,7 +130,7 @@ class StreamFile:
         """
         data_config = self.get_stream_config(stream_name)
         data_path = data_config["path"]
-        timestamps = self.hdf5_file[data_path].get("timestamps", default=None)
+        timestamps = self.hdf5_file[data_path].attrs.get("timestamps", default=None)
         if timestamps is not None:
             if isinstance(timestamps, np.ndarray) and len(timestamps) == 1 and isinstance(timestamps[0], np.bytes_):
                 timestamps = timestamps[0]
@@ -179,7 +179,7 @@ class StreamFile:
             unsort_index = np.argsort(index_order)  # ordering that would make sorted `index` back as before sorting.
             #data = np.stack([self.hdf5_file[data_path][np.array(index)[index_order]][unsort_index]])
             data = self.hdf5_file[data_path][np.array(index)[index_order]][unsort_index]
-        if isinstance(index, int):
+        elif isinstance(index, int):
             #data = np.stack([self.hdf5_file[data_path][index]])
             data = self.hdf5_file[data_path][index]
         else:
@@ -221,7 +221,7 @@ class StreamFile:
             shape = (1,) + data.shape
             max_shape = (None,) + data.shape
             # chunk enabled automatically with maxshape
-            self.hdf5_file.create_dataset(name, shape=shape, data=data, chunk=True, maxshape=max_shape)
+            self.hdf5_file.create_dataset(name, shape=shape, data=data, chunks=True, maxshape=max_shape)
         else:
             index = self.hdf5_file[name].shape[0]
             self.hdf5_file[name].resize(index + 1, axis=0)
diff --git a/bob/io/stream/test/test_streams.py b/bob/io/stream/test/test_streams.py
index eee4aaa..89ddfc1 100644
--- a/bob/io/stream/test/test_streams.py
+++ b/bob/io/stream/test/test_streams.py
@@ -35,7 +35,7 @@ def test_stream_write():
     test_data = [
         np.arange(5 * 3 * 40 * 52, dtype=np.int16).reshape((5, 3, 40, 52)),
         np.arange(5 * 1 * 5 * 5, dtype=np.int8).reshape((5, 1, 5, 5)),
-        np.arange(1 * 1 * 500 * 400).astype(np.float).reshape((1, 1, 500, 400)),
+        np.arange(1 * 1 * 500 * 400).astype(float).reshape((1, 1, 500, 400)),
         np.arange(12 * 52).astype(np.float64).reshape((12, 52)),
     ]
 
@@ -77,8 +77,8 @@ def test_stream():
 
     # create data file
     f = h5py.File(resource_path("test/data/stream_test.h5"), "w")
-    f.set("data_a", data_a)
-    f.set("data_b", data_b)
+    f["data_a"] = data_a
+    f["data_b"] = data_b
     del f
 
     # Streams attributes when config is specified
-- 
GitLab