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

validating an OrderedDict returns an unordered dict #254

Closed
SimplyKnownAsG opened this issue Dec 7, 2016 · 0 comments
Closed

validating an OrderedDict returns an unordered dict #254

SimplyKnownAsG opened this issue Dec 7, 2016 · 0 comments

Comments

@SimplyKnownAsG
Copy link
Contributor

It would be nice if the returned dictionary from validation were the same type as the original.

For example, if I validate an OrderedDict of (x,y) pairs, the order may be important and converting to a traditional dict doesn't maintain the order. I suppose it is also possible that one could request the validator be ordered as well and I'm not sure what that would mean.

Example:

import numpy
import collections
from voluptuous import Schema, Number

schema = Schema({Number(): Number()}) # x, y pairs (for interpolation or something)
data = collections.OrderedDict(zip(numpy.linspace(5, 100, 11), numpy.random.random(11)))
out = schema(data)
assert isinstance(out, collections.OrderedDict),\
    'Collection is no longer ordered, order:{}'.format(', '.join(str(k) for k in out.keys()))

This may be related to #40, but I don't quite understand what the issue was there.

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