From abc0efe8ad66b5120d2dab1d9f4d6e0c90eadb02 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Tue, 5 Nov 2024 18:47:07 -0600 Subject: [PATCH 1/3] small patch to html repr --- src/hdmf/backends/hdf5/h5tools.py | 35 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/hdmf/backends/hdf5/h5tools.py b/src/hdmf/backends/hdf5/h5tools.py index e9156dc50..5323f99b4 100644 --- a/src/hdmf/backends/hdf5/h5tools.py +++ b/src/hdmf/backends/hdf5/h5tools.py @@ -1609,23 +1609,26 @@ def set_dataio(cls, **kwargs): def generate_dataset_html(dataset): """Generates an html representation for a dataset for the HDF5IO class""" - # get info from hdf5 dataset - compressed_size = dataset.id.get_storage_size() - if hasattr(dataset, "nbytes"): # TODO: Remove this after h5py minimal version is larger than 3.0 - uncompressed_size = dataset.nbytes - else: - uncompressed_size = dataset.size * dataset.dtype.itemsize - compression_ratio = uncompressed_size / compressed_size if compressed_size != 0 else "undefined" - - hdf5_info_dict = {"Chunk shape": dataset.chunks, - "Compression": dataset.compression, - "Compression opts": dataset.compression_opts, - "Compression ratio": compression_ratio} - - # get basic array info array_info_dict = get_basic_array_info(dataset) - array_info_dict.update(hdf5_info_dict) - + if isinstance(dataset, h5py.Dataset): + + # get info from hdf5 dataset + compressed_size = dataset.id.get_storage_size() + if hasattr(dataset, "nbytes"): # TODO: Remove this after h5py minimal version is larger than 3.0 + uncompressed_size = dataset.nbytes + else: + uncompressed_size = dataset.size * dataset.dtype.itemsize + compression_ratio = uncompressed_size / compressed_size if compressed_size != 0 else "undefined" + + hdf5_info_dict = { + "Chunk shape": dataset.chunks, + "Compression": dataset.compression, + "Compression opts": dataset.compression_opts, + "Compression ratio": compression_ratio, + } + + array_info_dict.update(hdf5_info_dict) + # generate html repr repr_html = generate_array_html_repr(array_info_dict, dataset, "HDF5 dataset") From 1fc58799420419305185eb425353ae1536309ef1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 Nov 2024 01:06:07 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/hdmf/backends/hdf5/h5tools.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hdmf/backends/hdf5/h5tools.py b/src/hdmf/backends/hdf5/h5tools.py index 5323f99b4..765ff6aa5 100644 --- a/src/hdmf/backends/hdf5/h5tools.py +++ b/src/hdmf/backends/hdf5/h5tools.py @@ -1611,7 +1611,7 @@ def generate_dataset_html(dataset): array_info_dict = get_basic_array_info(dataset) if isinstance(dataset, h5py.Dataset): - + # get info from hdf5 dataset compressed_size = dataset.id.get_storage_size() if hasattr(dataset, "nbytes"): # TODO: Remove this after h5py minimal version is larger than 3.0 @@ -1619,16 +1619,16 @@ def generate_dataset_html(dataset): else: uncompressed_size = dataset.size * dataset.dtype.itemsize compression_ratio = uncompressed_size / compressed_size if compressed_size != 0 else "undefined" - + hdf5_info_dict = { "Chunk shape": dataset.chunks, "Compression": dataset.compression, "Compression opts": dataset.compression_opts, "Compression ratio": compression_ratio, } - + array_info_dict.update(hdf5_info_dict) - + # generate html repr repr_html = generate_array_html_repr(array_info_dict, dataset, "HDF5 dataset") From 35915d1ad2d6f033971a6b7cba2ff8a3bf067322 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Sat, 9 Nov 2024 12:02:56 -0600 Subject: [PATCH 3/3] comment request --- src/hdmf/container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hdmf/container.py b/src/hdmf/container.py index 8f961936f..4ee24ec2d 100644 --- a/src/hdmf/container.py +++ b/src/hdmf/container.py @@ -754,7 +754,7 @@ def _generate_array_html(self, array, level): """Generates HTML for array data""" read_io = self.get_read_io() # if the Container was read from file, get IO object - if read_io is not None: + if read_io is not None: # Note that sometimes numpy array have a read_io attribute repr_html = read_io.generate_dataset_html(array) else: array_info_dict = get_basic_array_info(array)