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

Add escape function to escape dots in field names #1326

Closed
sotte opened this issue Feb 7, 2019 · 1 comment
Closed

Add escape function to escape dots in field names #1326

sotte opened this issue Feb 7, 2019 · 1 comment

Comments

@sotte
Copy link

sotte commented Feb 7, 2019

By default altair/vaga uses dots and brackets in in field names to access nested objects. Dots are quite common in field names and don't necessarily indicate nested attributes. One has to manually escape the dot.

I'm proposing to add an escape() function that does exactly that, it escapes a field name that contains a dot. I could implement the PR.

The implementation would look something like this:

def escape(name: str) -> str:
    """
    >>> escape("foo.bar")
    "foo\\.bar"
    >>> escape("foo_bar")
    "foo_bar"
    """
    return name.replace(".", "\\.")

Questions:

  • Is it worth to add this function?
  • Where should we put it? I don't know the project enough to have a qualified
    oppinion. Maybe altair/utils/core.py?
  • Should the function be importable from the altiar top level package? I.e. it
    can be used like this: alt.escape("foo.bar").

Ref taken from the docs:

Note: Dots (.) and brackets ([ and ]) can be used to access nested objects
(e.g., "field": "foo.bar" and "field": "foo['bar']").
If field names contain dots or brackets but are not nested,
you can use \ to escape dots and brackets (e.g., "a\.b" and "a\[0\]").
See more details about escaping in the field documentation.

This ticket is the result of the discussion in #284 (comment).

@joelostblom
Copy link
Contributor

Looking through some old issues, I am unsure about the value added here. It seems easier to type "foo\.bar" than alt.escape("foo.bar"). I will close this for now, but feel free to comment if you think it should be re-opened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants