Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #250 from simphony/dtype-uuid-UUID
Browse files Browse the repository at this point in the history
Keyword.dtype=uuid.UUID and fixes
  • Loading branch information
kitchoi committed Dec 15, 2015
2 parents 4f4257e + 8739c74 commit 2c15ac8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
3 changes: 2 additions & 1 deletion simphony/core/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import namedtuple

import numpy
import uuid


ATTRIBUTES = [
Expand Down Expand Up @@ -561,5 +562,5 @@
key='MATERIAL',
number=68,
shape=[1],
dtype='uuid'),
dtype=uuid.UUID),
}
4 changes: 2 additions & 2 deletions simphony/io/data_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def convert_to_file_type(value, cuba):
The value in a form suitable for storage
"""
if KEYWORDS[CUBA(cuba).name].dtype == 'uuid':
if KEYWORDS[CUBA(cuba).name].dtype is uuid.UUID:
return value.hex
else:
return value
Expand All @@ -48,7 +48,7 @@ def convert_from_file_type(file_value, cuba):
The value which has the type as described in CUBA
"""
if KEYWORDS[CUBA(cuba).name].dtype == 'uuid':
if KEYWORDS[CUBA(cuba).name].dtype is uuid.UUID:
return uuid.UUID(hex=file_value, version=4)
else:
return file_value
4 changes: 2 additions & 2 deletions simphony/testing/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def test_dummy_cuba_value(self):
for cuba in CUBA:
value = dummy_cuba_value(cuba)
keyword = KEYWORDS[CUBA(cuba).name]
if keyword.dtype == "uuid":
if keyword.dtype is uuid.UUID:
self.assertEqual(value, uuid.UUID(int=constant, version=4))
elif numpy.issubdtype(keyword.dtype, str):
self.assertEqual(value, keyword.name + str(constant))
Expand All @@ -931,7 +931,7 @@ def test_dummy_cuba_value_with_constant(self):
for cuba in CUBA:
value = dummy_cuba_value(cuba, constant=18)
keyword = KEYWORDS[CUBA(cuba).name]
if keyword.dtype == "uuid":
if keyword.dtype is uuid.UUID:
self.assertEqual(value, uuid.UUID(int=constant, version=4))
elif numpy.issubdtype(keyword.dtype, str):
self.assertEqual(value, keyword.name + str(constant))
Expand Down
19 changes: 7 additions & 12 deletions simphony/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,24 +335,19 @@ def dummy_cuba_value(cuba, constant=None):
if constant is None:
constant = 3
keyword = KEYWORDS[CUBA(cuba).name]
if keyword.dtype == "uuid":
if keyword.dtype is uuid.UUID:
return uuid.UUID(int=constant, version=4)
elif numpy.issubdtype(keyword.dtype, str):
return keyword.name + str(constant)
else:
elif (numpy.issubdtype(keyword.dtype, numpy.float) or
numpy.issubdtype(keyword.dtype, numpy.int)):
shape = keyword.shape
if shape == [1]:
if numpy.issubdtype(keyword.dtype, 'float'):
return float(cuba + constant)
if numpy.issubdtype(keyword.dtype, 'int'):
return int(cuba + constant)
return keyword.dtype(cuba+constant)
else:
data = numpy.arange(numpy.prod(shape)) * (cuba + constant)
data = numpy.reshape(data, shape)
if numpy.issubdtype(keyword.dtype, 'float'):
return numpy.ones(shape=shape, dtype=numpy.float64) * data
if numpy.issubdtype(keyword.dtype, 'int'):
return numpy.ones(shape=shape, dtype=numpy.int32) * data
data = numpy.arange(numpy.prod(shape),
dtype=keyword.dtype)*(cuba+constant)
return data.reshape(shape)

raise RuntimeError(
'cannot create value for {}'.format(keyword.dtype))
Expand Down

0 comments on commit 2c15ac8

Please sign in to comment.