Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions src/hdmf/backends/hdf5/h5tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,23 +1538,40 @@
"""Generates an html representation for a dataset for the HDF5IO class"""

array_info_dict = get_basic_array_info(dataset)
if isinstance(dataset, h5py.Dataset):
if isinstance(dataset, str):
dataset_type = "String data"

Check warning on line 1542 in src/hdmf/backends/hdf5/h5tools.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/backends/hdf5/h5tools.py#L1542

Added line #L1542 was not covered by tests
# For string data from LINDI, add basic info about the string
string_info_dict = {

Check warning on line 1544 in src/hdmf/backends/hdf5/h5tools.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/backends/hdf5/h5tools.py#L1544

Added line #L1544 was not covered by tests
"Size": len(dataset),
"Type": "string"
}
array_info_dict.update(string_info_dict)

Check warning on line 1548 in src/hdmf/backends/hdf5/h5tools.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/backends/hdf5/h5tools.py#L1548

Added line #L1548 was not covered by tests
elif isinstance(dataset, h5py.Dataset):
dataset_type = "HDF5 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)

array_info_dict.update({

Check warning on line 1552 in src/hdmf/backends/hdf5/h5tools.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/backends/hdf5/h5tools.py#L1552

Added line #L1552 was not covered by tests
"Chunk shape": dataset.chunks,
})

if hasattr(dataset, "id") and hasattr(dataset.id, "get_storage_size"):
compressed_size = dataset.id.get_storage_size()

Check warning on line 1557 in src/hdmf/backends/hdf5/h5tools.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/backends/hdf5/h5tools.py#L1557

Added line #L1557 was not covered by tests

# get info from hdf5 dataset
if hasattr(dataset, "nbytes"):
uncompressed_size = dataset.nbytes

Check warning on line 1561 in src/hdmf/backends/hdf5/h5tools.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/backends/hdf5/h5tools.py#L1561

Added line #L1561 was not covered by tests
else:
uncompressed_size = dataset.size * dataset.dtype.itemsize
compression_ratio = uncompressed_size / compressed_size if compressed_size != 0 else "undefined"
array_info_dict.update({"Compression ratio": compression_ratio})

Check warning on line 1565 in src/hdmf/backends/hdf5/h5tools.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/backends/hdf5/h5tools.py#L1563-L1565

Added lines #L1563 - L1565 were not covered by tests

try:
array_info_dict.update({

Check warning on line 1568 in src/hdmf/backends/hdf5/h5tools.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/backends/hdf5/h5tools.py#L1567-L1568

Added lines #L1567 - L1568 were not covered by tests
"Compression": dataset.compression,
"Compression opts": dataset.compression_opts,
})
except:

Check failure on line 1572 in src/hdmf/backends/hdf5/h5tools.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E722)

src/hdmf/backends/hdf5/h5tools.py:1572:13: E722 Do not use bare `except`
pass # doesn't work for LINDI

Check warning on line 1573 in src/hdmf/backends/hdf5/h5tools.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/backends/hdf5/h5tools.py#L1572-L1573

Added lines #L1572 - L1573 were not covered by tests


elif isinstance(dataset, np.ndarray):
dataset_type = "NumPy array"
Expand Down
2 changes: 1 addition & 1 deletion src/hdmf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@
# Heuristic for displaying data
array_is_small = array_size_bytes < 1024 * 0.1 # 10 % a kilobyte to display the array
if array_is_small:
repr_html += "<br>" + str(np.asarray(array))
repr_html += "<br>" + str(array[()])

Check warning on line 932 in src/hdmf/utils.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/utils.py#L932

Added line #L932 was not covered by tests

return repr_html

Expand Down
Loading