From f804d13650636aff69f5c60b6c8eb8ed39cfdc5d Mon Sep 17 00:00:00 2001 From: Ray Osborn Date: Thu, 28 Nov 2019 16:57:10 -0600 Subject: [PATCH 1/2] Add functions to test to determine string and numeric dtypes --- src/nexusformat/nexus/tree.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/nexusformat/nexus/tree.py b/src/nexusformat/nexus/tree.py index 0e1dac4..2f7645c 100644 --- a/src/nexusformat/nexus/tree.py +++ b/src/nexusformat/nexus/tree.py @@ -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: From 7bd23bb6a795a13573f2cd2fe32903da066ac81b Mon Sep 17 00:00:00 2001 From: Ray Osborn Date: Sat, 30 Nov 2019 09:35:24 -0600 Subject: [PATCH 2/2] Add pytests for the new functions --- tests/test_fields.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_fields.py b/tests/test_fields.py index 77dd37a..623dd8b 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -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 @@ -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 @@ -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)))