Skip to content

Commit

Permalink
[block] add label and unit as optional args for array creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrewe committed Jun 18, 2021
1 parent 130fab2 commit d0250d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nixio/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def create_group(self, name, type_):

def create_data_array(self, name="", array_type="", dtype=None, shape=None,
data=None, compression=Compression.Auto,
copy_from=None, keep_copy_id=True):
copy_from=None, keep_copy_id=True, label=None, unit=None):
"""
Create/copy a new data array for this block. Either ``shape``
or ``data`` must be given. If both are given their shape must agree.
Expand All @@ -219,6 +219,10 @@ def create_data_array(self, name="", array_type="", dtype=None, shape=None,
:type copy_from: DataArray
:param keep_copy_id: Specify if the id should be copied in copy mode
:type keep_copy_id: bool
:param label: The label, defaults to None.
:type label: str
:param unit: The unit of the stored data. Defaults to None.
:type unit: str
:returns: The newly created data array.
:rtype: :class:`~nixio.DataArray`
Expand Down Expand Up @@ -254,6 +258,8 @@ def create_data_array(self, name="", array_type="", dtype=None, shape=None,
dtype, shape, compression)
if data is not None:
da.write_direct(data)
da.unit = unit
da.label = label
return da

def create_data_frame(self, name="", type_="", col_dict=None,
Expand Down
13 changes: 13 additions & 0 deletions nixio/test/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ def test_block_data_arrays(self):

assert len(self.block.data_arrays) == 0

data_array = self.block.create_data_array("test data_array",
"recordingsession",
nix.DataType.Int32, (0, ), label="voltage", unit="V")

assert len(self.block.data_arrays) == 1
assert data_array.unit == "V"
assert data_array.label == "voltage"

del self.block.data_arrays[0]

assert len(self.block.data_arrays) == 0


def test_block_multi_tags(self):
assert len(self.block.multi_tags) == 0

Expand Down

0 comments on commit d0250d9

Please sign in to comment.