Skip to content

Commit

Permalink
Merge pull request #114 from rayosborn/add-field-tests
Browse files Browse the repository at this point in the history
Add NXfield test functions
  • Loading branch information
rayosborn authored Nov 30, 2019
2 parents 7e3a399 + 7bd23bb commit 615965e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/nexusformat/nexus/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3835,6 +3835,14 @@ def plot_rank(self):
"""Rank of the NXfield when plotting."""
return len(self.plot_shape)

def is_numeric(self):
"""True if the NXfield contains numeric data."""
return not is_string_dtype(self.dtype)

def is_string(self):
"""True if the NXfield contains strings."""
return is_string_dtype(self.dtype)

def is_plottable(self):
"""True if the NXfield is plottable."""
if self.plot_rank > 0:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_string_field_creation(text):

assert field.nxvalue == text
assert field.dtype == string_dtype
assert field.is_string()
assert len(field) == 0


Expand All @@ -29,6 +30,7 @@ def test_byte_field_creation(text):
assert field.nxvalue == text
assert field.nxdata.decode(NX_ENCODING) == text
assert field.dtype != string_dtype
assert field.is_string()
assert len(field) == 0


Expand All @@ -42,6 +44,7 @@ def test_array_field_creation(arr):
assert field.shape == arr.shape
assert field.dtype == arr.dtype
assert field.size == arr.size
assert field.is_numeric()
assert len(field) == len(arr)
assert field.reshape((field.size)) == NXfield(arr.reshape((arr.size)))

Expand Down

0 comments on commit 615965e

Please sign in to comment.