-
Notifications
You must be signed in to change notification settings - Fork 12
Improve line removal in model piping #879
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
Draft
billdenney
wants to merge
8
commits into
main
Choose a base branch
from
878-cannot-remove-an-if-block-via-model-piping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
756a1a5
`fit |> model(-a ~ NULL)` can now remove a model estimation line
billdenney daff702
Capture any NULL assignment for dropping
billdenney 27192bc
Generalize any subtraction is a removal
billdenney 0789627
Code reformatting (no changes)
billdenney bd5b7c9
Change input to `modelVars` from `rxui` to simplify testing; add many…
billdenney b7d60f3
Fix test
billdenney 7eca306
Enumerate all expected combinations of drop lines
billdenney 95e4607
Remove tests for dropping if blocks
billdenney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| test_that(".isDropExpression", { | ||
| # Test .getModelLineEquivalentLhsExpressionDropDdt | ||
| expect_true(.isDropExpression(str2lang("-d/dt(a)"))) | ||
| expect_true(.isDropExpression(str2lang("d/dt(a) <- NULL"))) | ||
| expect_true(.isDropExpression(str2lang("d/dt(a) = NULL"))) | ||
| expect_false(.isDropExpression(str2lang("d/dt(a)"))) | ||
| # Test .getModelLineEquivalentLhsExpressionDropEndpoint | ||
| expect_true(.isDropExpression(str2lang("-a ~ ."))) | ||
| expect_true(.isDropExpression(str2lang("-a ~ NULL"))) | ||
| expect_false(.isDropExpression(str2lang("a ~ ."))) | ||
|
|
||
| # Test assignment dropping | ||
| expect_true(.isDropExpression(str2lang("-a"))) | ||
| expect_true(.isDropExpression(str2lang("a <- NULL"))) | ||
| expect_true(.isDropExpression(str2lang("a = NULL"))) | ||
| expect_false(.isDropExpression(str2lang("a <- ."))) | ||
|
|
||
| # Test special assignment dropping | ||
| expect_true(.isDropExpression(str2lang("-lag(a)"))) | ||
| expect_true(.isDropExpression(str2lang("lag(a) <- NULL"))) | ||
| expect_false(.isDropExpression(str2lang("lag(a) <- b"))) | ||
|
|
||
| # Test for if blocks | ||
| expect_false(.isDropExpression(str2lang("if (.) ."))) | ||
| }) | ||
|
|
||
| test_that(".getModelineFromExpressionsAndOriginalLines", { | ||
| origLines <- | ||
| list( | ||
| str2lang("a <- 1"), | ||
| str2lang("b <- 2"), | ||
| str2lang("if (a == 1) { b <- 2}"), | ||
| str2lang("a~foo") | ||
| ) | ||
|
|
||
| # `useErrorLine = FALSE` (all lines with `a` on the LHS are returned) | ||
| expect_equal( | ||
| .getModelineFromExpressionsAndOriginalLines( | ||
| expr = as.name("a"), | ||
| altExpr = NULL, | ||
| useErrorLine = FALSE, | ||
| errLines = 4, | ||
| origLines = origLines, | ||
| modelVars = "a", | ||
| returnAllLines = TRUE | ||
| ), | ||
| c(1, 4) | ||
| ) | ||
| # `useErrorLine = TRUE` and `returnAllLines = FALSE` | ||
| # no lines with `a` on the LHS are returned | ||
| ## TODO: Is this the intended behavior? I expected line 1 to be returned. | ||
| expect_null( | ||
| .getModelineFromExpressionsAndOriginalLines( | ||
| expr = as.name("a"), | ||
| altExpr = NULL, | ||
| useErrorLine = TRUE, | ||
| errLines = 4, | ||
| origLines = origLines, | ||
| modelVars = "a", | ||
| returnAllLines = TRUE | ||
| ) | ||
| ) | ||
| # `useErrorLine = FALSE` and `returnAllLines = FALSE` | ||
| # only the first line with `a` on the LHS is returned | ||
| expect_equal( | ||
| .getModelineFromExpressionsAndOriginalLines( | ||
| expr = as.name("a"), | ||
| altExpr = NULL, | ||
| useErrorLine = FALSE, | ||
| errLines = 4, | ||
| origLines = origLines, | ||
| modelVars = "a", | ||
| returnAllLines = FALSE | ||
| ), | ||
| 1 | ||
| ) | ||
| # `useErrorLine = TRUE` and `returnAllLines = FALSE` | ||
| # only the error model line with `a` on the LHS is returned | ||
| expect_equal( | ||
| .getModelineFromExpressionsAndOriginalLines( | ||
| expr = as.name("a"), | ||
| altExpr = NULL, | ||
| useErrorLine = TRUE, | ||
| errLines = 4, | ||
| origLines = origLines, | ||
| modelVars = "a", | ||
| returnAllLines = FALSE | ||
| ), | ||
| 4 | ||
| ) | ||
|
|
||
| # `useErrorLine = TRUE` and `returnAllLines = FALSE`; altExpr gives the actual value | ||
| # `d` is never an LHS value so NULL is returned | ||
| # TODO: It's unclear why the warning "with single endpoint model prediction 'a' is changed to 'd'" occurs. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattfidler, Can you please take a look at this? The output makes sense to me, but the warning suggests that the model is changed when it is not. I'm not sure what the intent of the warning is. |
||
| expect_null( | ||
| .getModelineFromExpressionsAndOriginalLines( | ||
| expr = as.name("d"), | ||
| altExpr = NULL, | ||
| useErrorLine = TRUE, | ||
| errLines = 4, | ||
| origLines = origLines, | ||
| modelVars = "a", | ||
| returnAllLines = TRUE | ||
| ) | ||
| ) | ||
|
|
||
| # `useErrorLine = TRUE` and `returnAllLines = FALSE`; altExpr gives the actual value | ||
| # It ends up working the same as if `a` were the `expr` argument. | ||
| expect_equal( | ||
| .getModelineFromExpressionsAndOriginalLines( | ||
| expr = as.name("d"), | ||
| altExpr = as.name("a"), | ||
| useErrorLine = TRUE, | ||
| errLines = 4, | ||
| origLines = origLines, | ||
| modelVars = "a", | ||
| returnAllLines = TRUE | ||
| ), | ||
| c(1, 4) | ||
| ) | ||
|
|
||
| # `useErrorLine = TRUE` and `returnAllLines = FALSE`; variable is the LHS of the error expression but not part of the modelVars | ||
| # Returns 3 | ||
| expect_equal( | ||
| .getModelineFromExpressionsAndOriginalLines( | ||
| expr = as.name("a"), | ||
| altExpr = NULL, | ||
| useErrorLine = TRUE, | ||
| errLines = 3, | ||
| origLines = origLines[2:4], | ||
| modelVars = c(), | ||
| returnAllLines = FALSE | ||
| ), | ||
| 3 | ||
| ) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattfidler, Can you please take a look at this? I think it may be a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is a bug, I think this is used in
modelExtract(), but I could be wrong.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I don't understand what you are trying to do enough to say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm trying to do immediately is have simpler tests to understand the methods used. Then, with simpler tests, I can make modifications knowing that I won't accidentally break anything (and I don't have to wait for the full test suite to run).
So, overall right now, I'm adding tests for code behavior and logically checking that there aren't any accidental bugs. (I did find one where
model(a ~ NULL)would not remove the line.) It sounds like this one is intended as-is.