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

"+ -1" equivalence with "-1" in patsy formula? #158

Open
lebedov opened this issue Jul 20, 2020 · 2 comments
Open

"+ -1" equivalence with "-1" in patsy formula? #158

lebedov opened this issue Jul 20, 2020 · 2 comments
Assignees
Labels

Comments

@lebedov
Copy link

lebedov commented Jul 20, 2020

As per patsy's documentation, the following results in a design matrix with no intercept:

>>> patsy.dmatrix('a + b - 1',
       pandas.DataFrame({'a':[1,2], 'b':[3,4]}))
DesignMatrix with shape (2, 2)
  a  b
  1  3
  2  4
  Terms:
    'a' (column 0), 'b' (column 1)

The documentation seems to imply that appending + -1 to the formula a + b should have the same effect as appending '-1'; however, it doesn't seem that the intercept is removed for the former:

>>> patsy.dmatrix('a + b + -1',
       pandas.DataFrame({'a':[1,2],'b':[3,4]}))
DesignMatrix with shape (2, 3)
  Intercept  a  b
          1  1  3
          1  2  4
  Terms:
    'Intercept' (column 0)
    'a' (column 1)
    'b' (column 2)

Is the above expected?

I'm using patsy 0.5.1 with python 3.7.6 and pandas 1.0.5.

@matthewwardrop matthewwardrop self-assigned this Sep 25, 2021
@matthewwardrop
Copy link
Collaborator

Thanks for reporting this @lebedov. This does look like a bug, and despite the feature freeze, probably one worth patching. I'll look into it when I get a chance.

Note that this works in patsy's upcoming successor Formulaic as expected:

from formulaic import Formula

Formula('a + b + -1')  # Outputs: a + b

@lebedov
Copy link
Author

lebedov commented Sep 26, 2021

Thanks for letting me know about Formulaic!

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

No branches or pull requests

2 participants