-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
This is relevant for scaper's schema e.g.:
"pitch_shift": {
"type": ["number", "null"]
},It should be handled similar to oneOf:
def __get_dtype(typespec):
'''Get the dtype associated with a jsonschema type definition
Parameters
----------
typespec : dict
The schema definition
Returns
-------
dtype : numpy.dtype
The associated dtype
'''
if 'type' in typespec:
if isinstance(typespec['type'], (list, tuple)):
# get dtype for each type in list
types = [__TYPE_MAP__.get(t, np.object_) for t in typespec['type']]
# If they're not all equal, return object
if all([t == types[0] for t in types]):
return types[0]
return np.object_
else:
return __TYPE_MAP__.get(typespec['type'], np.object_)
elif 'enum' in typespec:
# Enums map to objects
return np.object_
elif 'oneOf' in typespec:
# Recurse
types = [__get_dtype(v) for v in typespec['oneOf']]
# If they're not all equal, return object
if all([t == types[0] for t in types]):
return types[0]
return np.object_Metadata
Metadata
Assignees
Labels
No labels