Skip to content

Commit

Permalink
Merge pull request #464 from achilleas-k/odml-dtypes
Browse files Browse the repository at this point in the history
Fixes and simplifications for DataTypes and DataType mappings
  • Loading branch information
jgrewe authored May 13, 2020
2 parents 7ce8de0 + f58447c commit 2e6491f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
15 changes: 5 additions & 10 deletions nixio/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
7 changes: 3 additions & 4 deletions nixio/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2e6491f

Please sign in to comment.