From ea6504f6c49e78d7b3d0effccef2bd1fe19520ab Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Mon, 11 Nov 2024 11:55:07 -0600 Subject: [PATCH] Small patch to html repr in #1100 (#1201) * small patch to html repr * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * comment request --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Steph Prince <40640337+stephprince@users.noreply.github.com> --- src/hdmf/backends/hdf5/h5tools.py | 31 +++++++++++++++++-------------- src/hdmf/container.py | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/hdmf/backends/hdf5/h5tools.py b/src/hdmf/backends/hdf5/h5tools.py index e9156dc50..765ff6aa5 100644 --- a/src/hdmf/backends/hdf5/h5tools.py +++ b/src/hdmf/backends/hdf5/h5tools.py @@ -1609,22 +1609,25 @@ 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" + array_info_dict = get_basic_array_info(dataset) + if isinstance(dataset, h5py.Dataset): - hdf5_info_dict = {"Chunk shape": dataset.chunks, - "Compression": dataset.compression, - "Compression opts": dataset.compression_opts, - "Compression ratio": compression_ratio} + # 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" - # get basic array info - array_info_dict = get_basic_array_info(dataset) - array_info_dict.update(hdf5_info_dict) + 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") 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)