Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__get_dtype fails when type is list #205

Open
beasteers opened this issue Sep 4, 2019 · 0 comments
Open

__get_dtype fails when type is list #205

beasteers opened this issue Sep 4, 2019 · 0 comments

Comments

@beasteers
Copy link

beasteers commented Sep 4, 2019

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_
@beasteers beasteers changed the title schema.__get_dtype fails when isinstance("type", list) __get_dtype fails when type is list Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant