Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Check]: TimeSeries with empty dataset #403

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Changes from 1 commit
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
23 changes: 21 additions & 2 deletions src/nwbinspector/checks/nwb_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import h5py
from pynwb import NWBContainer


from hdmf.utils import get_data_shape
from numpy import ndarray
from ..register_checks import register_check, Importance, InspectorMessage, Severity


Expand All @@ -28,6 +28,25 @@ def check_large_dataset_compression(nwb_container: NWBContainer, gb_lower_bound:
)


@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=NWBContainer)
def check_dataset_is_empty(nwb_container: NWBContainer):

def is_empty_data(data):
if isinstance(data, ndarray):
return data.size == 0
elif isinstance(data, (list, tuple)):
return all(is_empty_data(item) for item in data)
else:
return not bool(data)
Comment on lines +34 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind if this were moved to the common utils to be used by any other check (or anyone else) going forward 😃


if hasattr(nwb_container, "data"):
data = getattr(nwb_container, "data")
if is_empty_data(data):
return InspectorMessage(
message="Data object is empty. Please check the dataset before conversion"
)


@register_check(importance=Importance.BEST_PRACTICE_SUGGESTION, neurodata_type=NWBContainer)
def check_small_dataset_compression(
nwb_container: NWBContainer,
Expand Down
Loading