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

handle A ~ B - 1 and add tests #1086

Merged
merged 3 commits into from
Oct 3, 2016
Merged

Conversation

kleinschmidt
Copy link
Contributor

Fixes #574.

@@ -40,6 +40,9 @@ type Terms
intercept::Bool # is there an intercept column in the model matrix?
end

import Base.==
==(t1::Terms, t2::Terms) = all( getfield(t1, f)==getfield(t2, ) for f in fieldnames(t1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't seem to import functions in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not strictly necessary, just a convenience for testing Terms. I could move it to the test file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant that you should write Base.:(==)(...) = .... Though I just noticed f seems to be missing in getfield(t2, )?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would explain the test failures :) I tried it without the import first but didn't realize that Base.:(==) was the right way to refer to == in that context, thanks.

a3 = dospecials(excp)
if a1 == :-
a2, a3 = excp.args[2:3]
a3 == 1 || error("invalid expression $ex; subtraction only supported or -1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or -> for

t = Terms(y ~ -1 + x1 + x2)
@test t.intercept == false
@test t.terms == [:x1, :x2]
@test t == Terms(y ~ -1 + x1 + x2) == Terms(y ~ x1 - 1 + x2) == Terms(y ~ x1 + x2 -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also test for the error case?

@ararslan ararslan merged commit 400da84 into JuliaData:master Oct 3, 2016
nalimilan pushed a commit that referenced this pull request Jul 8, 2017
* handle -1 and add tests

* replace `import Base.==` with `Base.:(==)`

* typo and error test
nalimilan pushed a commit that referenced this pull request Jul 8, 2017
* handle -1 and add tests

* replace `import Base.==` with `Base.:(==)`

* typo and error test
rofinn pushed a commit that referenced this pull request Aug 17, 2017
* handle -1 and add tests

* replace `import Base.==` with `Base.:(==)`

* typo and error test
nalimilan pushed a commit that referenced this pull request Aug 25, 2017
* handle -1 and add tests

* replace `import Base.==` with `Base.:(==)`

* typo and error test
quinnj pushed a commit that referenced this pull request Sep 2, 2017
* handle -1 and add tests

* replace `import Base.==` with `Base.:(==)`

* typo and error test
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

Successfully merging this pull request may close these issues.

3 participants