Skip to content

Commit 450391f

Browse files
authored
Merge pull request #505 from jgrewe/array_create
[block] add label and unit as optional args for array creation
2 parents 91df1f8 + 3e225a4 commit 450391f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

nixio/block.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def create_group(self, name, type_):
196196

197197
def create_data_array(self, name="", array_type="", dtype=None, shape=None,
198198
data=None, compression=Compression.Auto,
199-
copy_from=None, keep_copy_id=True):
199+
copy_from=None, keep_copy_id=True, label=None, unit=None):
200200
"""
201201
Create/copy a new data array for this block. Either ``shape``
202202
or ``data`` must be given. If both are given their shape must agree.
@@ -219,6 +219,10 @@ def create_data_array(self, name="", array_type="", dtype=None, shape=None,
219219
:type copy_from: DataArray
220220
:param keep_copy_id: Specify if the id should be copied in copy mode
221221
:type keep_copy_id: bool
222+
:param label: The label, defaults to None.
223+
:type label: str
224+
:param unit: The unit of the stored data. Defaults to None.
225+
:type unit: str
222226
223227
:returns: The newly created data array.
224228
:rtype: :class:`~nixio.DataArray`
@@ -254,6 +258,8 @@ def create_data_array(self, name="", array_type="", dtype=None, shape=None,
254258
dtype, shape, compression)
255259
if data is not None:
256260
da.write_direct(data)
261+
da.unit = unit
262+
da.label = label
257263
return da
258264

259265
def create_data_frame(self, name="", type_="", col_dict=None,

nixio/test/test_block.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ def test_block_data_arrays(self):
8787

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

90+
data_array = self.block.create_data_array("test data_array",
91+
"recordingsession",
92+
nix.DataType.Int32, (0, ), label="voltage", unit="V")
93+
94+
assert len(self.block.data_arrays) == 1
95+
assert data_array.unit == "V"
96+
assert data_array.label == "voltage"
97+
98+
del self.block.data_arrays[0]
99+
100+
assert len(self.block.data_arrays) == 0
101+
102+
90103
def test_block_multi_tags(self):
91104
assert len(self.block.multi_tags) == 0
92105

0 commit comments

Comments
 (0)