Skip to content

Commit

Permalink
revert acceptance of data with no units and add test for timestamps a…
Browse files Browse the repository at this point in the history
…ssertion
  • Loading branch information
h-mayorquin committed Mar 21, 2024
1 parent bd19010 commit 583edd8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
7 changes: 2 additions & 5 deletions src/pynwb/ndx_binned_spikes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class BinnedAlignedSpikes(NWBDataInterface):
{
"name": "data",
"type": "array_data",
"shape": [(None, None, None), (None, None)],
"shape": [(None, None, None)],
"doc": "The source of the data",
},
{
Expand All @@ -84,7 +84,7 @@ def __init__(self, **kwargs):
keys_to_set = ("bin_width_in_milliseconds", "milliseconds_from_event_to_first_bin", "units")
args_to_set = popargs_to_dict(keys_to_set, kwargs)

keys_to_process = ("data", "event_timestamps") # these are properties and cannot be set with setattr
keys_to_process = ("data", "event_timestamps")
args_to_process = popargs_to_dict(keys_to_process, kwargs)
super().__init__(**kwargs)

Expand All @@ -94,9 +94,6 @@ def __init__(self, **kwargs):

# Post-process / post_init
data = args_to_process["data"]

data = data if data.ndim == 3 else data[np.newaxis, ...]

event_timestamps = args_to_process["event_timestamps"]

if data.shape[1] != event_timestamps.shape[0]:
Expand Down
29 changes: 10 additions & 19 deletions src/pynwb/tests/test_binned_aligned_spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,16 @@ def test_constructor_units_region(self):
expected_names = [unit_name_a, unit_name_c]
self.assertListEqual(unit_table_names, expected_names)

def test_accepting_input_with_no_number_of_units_dimension(self):

data = self.rng.integers(
low=0,
high=100,
size=(
self.number_of_event_repetitions,
self.number_of_bins,
),
)
binned_aligned_spikes = BinnedAlignedSpikes(
bin_width_in_milliseconds=self.bin_width_in_milliseconds,
milliseconds_from_event_to_first_bin=self.milliseconds_from_event_to_first_bin,
data=data,
event_timestamps=self.event_timestamps,
)

self.assertEqual(binned_aligned_spikes.data.shape, (1, self.number_of_event_repetitions, self.number_of_bins))

def test_constructor_inconsistent_timestamps_and_data_error(self):
shorter_timestamps = self.event_timestamps[:-1]

with self.assertRaises(ValueError):
BinnedAlignedSpikes(
bin_width_in_milliseconds=self.bin_width_in_milliseconds,
milliseconds_from_event_to_first_bin=self.milliseconds_from_event_to_first_bin,
data=self.data,
event_timestamps=shorter_timestamps,
)

class TestBinnedAlignedSpikesSimpleRoundtrip(TestCase):
"""Simple roundtrip test for BinnedAlignedSpikes."""
Expand Down

0 comments on commit 583edd8

Please sign in to comment.