Repository: NeurodataWithoutBorders/nwbinspector

Issue:
[Bug]: Compression check is wrongly triggered for large files
### What happened?

Currently, the warning is triggered if **there is** a compression indicator instead of being skipped as it should:

https://github.com/NeurodataWithoutBorders/nwbinspector/blob/fc7491baecd266f873fd023e26cdbe4121dfbd79/src/nwbinspector/checks/_nwb_containers.py#L29-L41

It seems that this error was introduced here:

https://github.com/NeurodataWithoutBorders/nwbinspector/pull/513/files#r1913569891

On PR #513 


### Operating System

None

### Python Version

None

### Were you streaming with ROS3?

None

### Package Versions

<details> Copy and paste your output here </details>

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/NeurodataWithoutBorders/nwbinspector/blob/dev/.github/CODE_OF_CONDUCT.rst)
- [X] Have you ensured this bug was not already [reported](https://github.com/neurodatawithoutborders/nwbinspector/issues)?
- [X] To the best of your ability, have you ensured this is a bug within the code that checks the NWBFile, rather than a bug in the NWBFile reader (e.g., [PyNWB](https://github.com/NeurodataWithoutBorders/pynwb) or [MatNWB](https://github.com/NeurodataWithoutBorders/matnwb))?

Discussion:

Solution patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2570988..ceb2b63 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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)
 
diff --git a/src/nwbinspector/checks/_nwb_containers.py b/src/nwbinspector/checks/_nwb_containers.py
index d48d170..69a2f23 100644
--- a/src/nwbinspector/checks/_nwb_containers.py
+++ b/src/nwbinspector/checks/_nwb_containers.py
@@ -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.",


Test patch:
diff --git a/tests/unit_tests/test_nwb_containers.py b/tests/unit_tests/test_nwb_containers.py
index 89142d5..8c7d5c6 100644
--- a/tests/unit_tests/test_nwb_containers.py
+++ b/tests/unit_tests/test_nwb_containers.py
@@ -92,6 +92,27 @@ class TestNWBContainers(TestCase):
             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="")