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 diff --git a/nixio/property.py b/nixio/property.py index bf18729a..cd9edf52 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 @@ -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