From b7d6717f804eebbfd0134b352d37e50a4520d1b2 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 8 May 2020 19:52:17 +0200 Subject: [PATCH 1/3] DataType: Expose Numeric type groups One for all Integers and one for the Floats. Simplifies the function for numeric detection, but it's probably unnecessary now. --- nixio/datatype.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/nixio/datatype.py b/nixio/datatype.py index f057c00e..daec3bbd 100644 --- a/nixio/datatype.py +++ b/nixio/datatype.py @@ -29,6 +29,10 @@ class DataType(object): String = np.unicode_ Bool = np.bool_ + # type groups + IntTypes = (Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64) + FloatTypes = (Float, Double) + @classmethod def get_dtype(cls, value): if isinstance(value, BOOLS): @@ -44,13 +48,4 @@ def get_dtype(cls, value): @classmethod def is_numeric_dtype(cls, dtype): - return (dtype == cls.Int8 or - dtype == cls.Int16 or - dtype == cls.Int32 or - dtype == cls.Int64 or - dtype == cls.UInt8 or - dtype == cls.UInt16 or - dtype == cls.UInt32 or - dtype == cls.UInt64 or - dtype == cls.Float or - dtype == cls.Double) + return dtype in cls.IntTypes + cls.FloatTypes From 1b6fc3220319c68ea6fa3b65dcad9c5cae3e8302 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 8 May 2020 19:56:22 +0200 Subject: [PATCH 2/3] Look for DataType.Double in odML compatibility check DataType.get_dtype() returns Double for all floating point values. Fixes #463. --- nixio/property.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixio/property.py b/nixio/property.py index bf18729a..c5093518 100644 --- a/nixio/property.py +++ b/nixio/property.py @@ -56,7 +56,7 @@ def compatible(self, value): DataType.get_dtype(value) == DataType.Bool): return True elif (self == self.Float and - DataType.get_dtype(value) == DataType.Float): + DataType.get_dtype(value) == DataType.Double): return True elif self == self.Int and DataType.get_dtype(value) == DataType.Int64: return True From f58447c590549368d83887190115ceb1d8d34e96 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 8 May 2020 19:59:29 +0200 Subject: [PATCH 3/3] Check against type groups when mapping NIX to odML --- nixio/property.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nixio/property.py b/nixio/property.py index c5093518..cd9edf52 100644 --- a/nixio/property.py +++ b/nixio/property.py @@ -77,10 +77,9 @@ def get_odml_type(cls, dtype): :param dtype: nix DataType :return: OdmlType """ - - if dtype == DataType.Float: + if dtype in DataType.FloatTypes: return cls.Float - elif dtype == DataType.Int64: + elif dtype in DataType.IntTypes: return cls.Int elif dtype == DataType.String: return cls.String