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

Allow VegaLite to accept either dict or JSON string? #33

Open
jakevdp opened this issue May 18, 2016 · 3 comments
Open

Allow VegaLite to accept either dict or JSON string? #33

jakevdp opened this issue May 18, 2016 · 3 comments

Comments

@jakevdp
Copy link
Contributor

jakevdp commented May 18, 2016

This came up in our chat – I think it's a good idea.

Could look something like this:

class Vegalite(object):
    def __init__(self, spec):
        try:
            spec = json.loads(spec)
        except TypeError:
            pass
        if 'data' not in spec:
            raise KeyError('No data provided with spec')
        self.spec = utils.update(spec, DEFAULTS, overwrite=False)

Advantage is more flexible API & ability to out-source dataframe formatting stuff to Pandas; the disadvantage is that in some situations we'd add an extra string->dict->string cycle.

@jakevdp
Copy link
Contributor Author

jakevdp commented May 18, 2016

Related question: are there any situations in which a valid Vega/Vegalite JSON string would be broken through doing spec = json.dumps(json.loads(spec))?

@domoritz
Copy link
Member

Related question: are there any situations in which a valid Vega/Vegalite JSON string would be broken through doing spec = json.dumps(json.loads(spec))?

I can't think of anything that could cause issues.

@jakevdp
Copy link
Contributor Author

jakevdp commented May 18, 2016

Another idea: I think it would make sense to let the Vegalite class take an optional data argument, that it would then roll into the dict/string spec (rather than having that part in an external function).

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

2 participants