Skip to content

Commit

Permalink
fix issue where check fails when description is a list in FeatureExtr…
Browse files Browse the repository at this point in the history
…action (#535)

* fix issue where check fails when description is a list in FeatureExtraction

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix handling of description=None

* fix handling of description=None

* update CHANGELOG

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Steph Prince <[email protected]>
  • Loading branch information
3 people authored Nov 26, 2024
1 parent 9e95262 commit 165c727
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upcoming

### Fixes
* Fixed issue where the description check failed if the description was a list. [#535](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/535)


# v0.6.0

### Deprecation
Expand Down
10 changes: 7 additions & 3 deletions src/nwbinspector/checks/_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ def check_description(neurodata_object: object) -> Optional[InspectorMessage]:
"""
if not hasattr(neurodata_object, "description"):
return None
if neurodata_object.description is None or neurodata_object.description.strip(" ") == "":

description = neurodata_object.description
if description is not None and type(description) is not str:
return None
if description is None or description.strip(" ") == "":
return InspectorMessage(message="Description is missing.")
if neurodata_object.description.lower().strip(".") in COMMON_DESCRIPTION_PLACEHOLDERS:
return InspectorMessage(message=f"Description ('{neurodata_object.description}') is a placeholder.")
if description.lower().strip(".") in COMMON_DESCRIPTION_PLACEHOLDERS:
return InspectorMessage(message=f"Description ('{description}') is a placeholder.")

return None
24 changes: 23 additions & 1 deletion tests/unit_tests/test_general.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from hdmf.common import DynamicTable
from hdmf.common import DynamicTable, DynamicTableRegion

from nwbinspector import Importance, InspectorMessage
from nwbinspector.checks import check_description, check_name_slashes
Expand Down Expand Up @@ -50,3 +50,25 @@ def test_check_description_missing():
object_name="test",
location="/",
)


def test_check_description_feature_extraction():
import numpy as np
from pynwb.ecephys import FeatureExtraction
from pynwb.testing.mock.ecephys import mock_ElectrodeTable

electrodes = mock_ElectrodeTable()

dynamic_table_region = DynamicTableRegion(
name="electrodes", description="I am wrong", data=[0, 1, 2, 3, 4], table=electrodes
)

feature_extraction = FeatureExtraction(
name="PCA_features",
electrodes=dynamic_table_region,
description=["PC1", "PC2", "PC3", "PC4"],
times=[0.033, 0.066, 0.099],
features=np.random.rand(3, 5, 4), # time, channel, feature
)

assert check_description(neurodata_object=feature_extraction) is None

0 comments on commit 165c727

Please sign in to comment.