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

Class appears to be a reserved word #129

Open
mortonjt opened this issue Aug 20, 2018 · 1 comment
Open

Class appears to be a reserved word #129

mortonjt opened this issue Aug 20, 2018 · 1 comment

Comments

@mortonjt
Copy link

@mortonjt mortonjt commented Aug 20, 2018

We had some users with qiime2 that had issues with passing in variables with "class" into the formula string.

Is "class" a reserved keyword. Full discussion is here: qiime2/q2-gneiss#24

@njsmith
Copy link
Member

@njsmith njsmith commented Aug 20, 2018

That's correct: class is a reserved word in Python, and since patsy allows arbitrary Python code inside formulas, Python's regular reserved-word rules apply to formulas too.

The workaround is to use patsy's quoting operator, Q. Like:

# doesn't work:
dmatrix("age + class", data=...)

# does work:
dmatrix("y ~ age + Q('class')", data=...)

I suppose we could hack around this by detecting reserved words that can't possibly appear inside an expression (e.g. class, for, def, ...), and "autoquoting" them, but I don't anticipate having time to work on this anytime soon.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.