Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion neo/io/nixio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,8 @@ def _write_property(self, section, name, v):
for item in v:
if isinstance(item, str):
item = item
elif isinstance(item, datetime_types):
item, definition = dt_to_nix(item)
elif isinstance(item, pq.Quantity):
current_unit = str(item.dimensionality)
if unit is None:
Expand Down Expand Up @@ -1320,7 +1322,10 @@ def _nix_attr_to_neo(nix_obj):
units = prop.unit
values = create_quantity(values, units)
if prop.definition in (DATEANNOTATION, TIMEANNOTATION, DATETIMEANNOTATION):
values = dt_from_nix(values, prop.definition)
if isinstance(values, list):
values = np.array([dt_from_nix(v, prop.definition) for v in values], dtype=object)
else:
values = dt_from_nix(values, prop.definition)
if prop.type == ARRAYANNOTATION:
if "array_annotations" in neo_attrs:
neo_attrs["array_annotations"][prop.name] = values
Expand Down
23 changes: 23 additions & 0 deletions neo/test/iotest/test_nixio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,29 @@ def test_empty_array_annotations(self):
else:
self.assertFalse(hasattr(rst.array_annotations[k], "units"))

def test_datetime_array_annotations(self):
# Regression test for GH Issue #1198: array_annotations holding
# datetime/date/time objects must survive a NixIO write/read roundtrip
wblock = Block("block with datetime array annotations")
wseg = Segment()
times = np.array([1.0, 2.0, 3.0]) * pq.s
datetime_array_annotations = {
"acq_datetime": np.array(
[datetime(2021, 1, 1, 0, 0, 0), datetime(2021, 6, 15, 12, 30, 0), datetime(2022, 3, 3, 8, 15, 30)],
dtype=object,
),
"acq_date": np.array([date(2021, 1, 1), date(2021, 6, 15), date(2022, 3, 3)], dtype=object),
"acq_time": np.array([time(0, 0, 0), time(12, 30, 0), time(8, 15, 30)], dtype=object),
}
wseg.events = [Event(times=times, array_annotations=datetime_array_annotations)]
wblock.segments = [wseg]
self.writer.write_block(wblock)
rblock = self.writer.read_block(neoname="block with datetime array annotations")
revent = rblock.segments[0].events[0]
for k, v in datetime_array_annotations.items():
self.assertIn(k, revent.array_annotations)
np.testing.assert_array_equal(revent.array_annotations[k], v)

def test_write_proxyobjects(self):

def generate_complete_block():
Expand Down
Loading