Skip to content

Commit

Permalink
Fix wrongly triggered compression check (#552)
Browse files Browse the repository at this point in the history
* fix error

* naming

* add test
  • Loading branch information
h-mayorquin authored Jan 14, 2025
1 parent 7fabc34 commit 870e1cd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
### Deprecation
* Remove s3fs dependency, which was causing dependency management issues [#549](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/549)

### Fixes
* Fix wrongly triggered compression check [#552](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/552)

## Improvements
* Added a section for describing the issues with negative timestamps in `TimeSeries` [#545](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/545)

Expand Down
3 changes: 2 additions & 1 deletion src/nwbinspector/checks/_nwb_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def check_large_dataset_compression(
elif isinstance(field, zarr.Array):
compression_indicator = field.compressor

if compression_indicator is not None and field.size * field.dtype.itemsize > gb_lower_bound * 1e9:
field_size_bytes = field.size * field.dtype.itemsize
if compression_indicator is None and field_size_bytes > gb_lower_bound * 1e9:
return InspectorMessage(
severity=Severity.HIGH,
message=f"{os.path.split(field.name)[1]} is a large uncompressed dataset! Please enable compression.",
Expand Down
21 changes: 21 additions & 0 deletions tests/unit_tests/test_nwb_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ def test_check_large_dataset_compression_below_20GB(self):
self.assertIsNone(obj=check_large_dataset_compression(nwb_container=nwb_container))


def test_no_error_raised_when_dataset_is_compressed():
"""Test that no InspectorMessage is returned for a compressed dataset."""
test_folder = Path(mkdtemp())
file_path = test_folder / "temp_test_file.nwb"

with h5py.File(name=str(file_path), mode="w") as file:
data = np.zeros(shape=(100, 100, 100)) # example small data shape
dataset = file.create_dataset(name="test_dataset", data=data, compression="gzip") # Enable compression

nwb_container = NWBContainer(name="test_container")
nwb_container.fields.update(dataset=dataset)

# Use a very low lower bound to simulate a large dataset threshold without a huge dataset
result = check_large_dataset_compression(nwb_container=nwb_container, gb_lower_bound=0.0001)

assert result is None

# Cleanup the temporary directory after the test
rmtree(test_folder)


def test_hit_check_empty_string_for_optional_attribute():
nwbfile = NWBFile(session_description="aa", identifier="aa", session_start_time=datetime.now(), pharmacology="")

Expand Down

0 comments on commit 870e1cd

Please sign in to comment.