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

train_continuous now preserves the class of the input #167

Merged
merged 7 commits into from
Sep 7, 2018

Conversation

billdenney
Copy link
Contributor

Fix #166

NEWS.md Outdated
@@ -67,6 +67,9 @@

* `rescale_mid()` now properly handles NAs (@foo-bar-baz-qux, #104).

* `train_continuous()` now maintains the class of inputs when they are not numeric
Copy link
Collaborator

Choose a reason for hiding this comment

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

@hadley is this going to make the release? I suspect it won't and this should actually be in its own new section up top:

# scales 1.0.0.9000

*  ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When this is resolved, I'll provide a new PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So no, this change will not be included in the 1.0.0 release. Please move this news bullet to the top with the new header I demonstrated above, and add your github handle and the issue number so that it follows style guidelines. No need to open a new PR, just make a new commit to your branch with the changes.

test_that("train_continuous maintains class", {
expect_equal(train_continuous(1:5),
c(1, 5),
info="Normal numeric input works with train_continuous")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please style your tests according to style.tidyverse.org? There should be space around each equal sign. The styler package can help with this.

@billdenney
Copy link
Contributor Author

I think that I got everything with this update.

NEWS.md Outdated
@@ -1,3 +1,10 @@
# scales 1.0.0.9000

## Minor bug fixes and improvements
Copy link
Collaborator

@dpseidel dpseidel Aug 7, 2018

Choose a reason for hiding this comment

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

This subheading is unnecessary when listing changes to the dev version, it's added when organizing changes just before release. Please remove it. Thanks for your patience with all these little nits -- you caught us right at release week so versions in NEWS and DESCRIPTION, haven't been bumped yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries. I'd be making similar comments on people submitting PRs to my repositories.

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

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

Sorry, just noticed I hadn't submitted my comments (I made them a while back)

@@ -38,7 +38,11 @@ train_continuous <- function(new, existing = NULL) {
if (is.factor(new) || !typeof(new) %in% c("integer", "double")) {
stop("Discrete value supplied to continuous scale", call. = FALSE)
}
suppressWarnings(range(existing, new, na.rm = TRUE, finite = TRUE))
if (is.null(existing)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why this is needed? I would expect range(NULL, x) to return the same type as x.

Copy link
Contributor Author

@billdenney billdenney Sep 7, 2018

Choose a reason for hiding this comment

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

I would have expected that, too, but it doesn't. If it did, then this entire PR would probably be unnecessary.

> range(as.POSIXct("2018-01-31"), NULL)
[1] "2018-01-31 EST" "2018-01-31 EST"
> range(NULL, as.POSIXct("2018-01-31"))
[1] 1517374800 1517374800
> 

Copy link
Member

Choose a reason for hiding this comment

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

Oh this is related to the type nightmare that is c().

Can you add a comment to that affect? i.e. range(NULL, x) strips attributes

@@ -19,3 +19,24 @@ test_that("NA.value works for discrete", {
expect_that(dscale(x, pal, "grey50")[1], equals("grey50"))
expect_that(dscale(x, pal, "grey50")[5], equals("grey50"))
})

test_that("train_continuous maintains class", {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please apply tidyverse style here too?

test_that("train_continuous maintains class", {
expect_equal(train_continuous(1:5),
c(1, 5),
info = "Normal numeric input works with train_continuous")
Copy link
Member

Choose a reason for hiding this comment

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

Please remove all uses of info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that, but why remove it? I find it to be useful to understand the underlying rationale for the test. Is there a preferred way to indicate rationale?

Copy link
Member

Choose a reason for hiding this comment

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

Rational should usually be encoded in the test name, or in a comment. In this case, I don't think that "Normal numeric input works with train_continuous" adds anything to my understanding of the test - it's implied by the test name that you'll be iterating through different types, and "working" is implied by expect_equal()

})

test_that("train_continuous with NULL input", {
expect_equal(train_continuous(new = NULL, existing = c(1, 5)),
Copy link
Member

Choose a reason for hiding this comment

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

It seems unnecessary to name both arguments to train_continuous()

@billdenney
Copy link
Contributor Author

@hadley, I think that I've resolved everything. There is a ≥ symbol apparently showing up somewhere in the documentation causing the manual build to fail, but I think that's unrelated to this PR

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

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

Thanks for all your work on this so far! A few more comments on the test organisation.

@@ -19,3 +19,36 @@ test_that("NA.value works for discrete", {
expect_that(dscale(x, pal, "grey50")[1], equals("grey50"))
expect_that(dscale(x, pal, "grey50")[5], equals("grey50"))
})

test_that(paste(
Copy link
Member

Choose a reason for hiding this comment

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

Can you please split this into two tests?

c(1, 5)
)
expect_error(train_continuous(LETTERS[1:5]),
regexp = "Discrete value supplied to continuous scale"
Copy link
Member

Choose a reason for hiding this comment

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

This regexp is a bit long - the point is to check that you're got the right error, not to validate the exact text of the error message.

Copy link
Member

Choose a reason for hiding this comment

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

But why is it in this test? It doesn't seem to be related to the topic of test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I've separated it into another test (and while not technically related to this PR's main topic, it is related to increasing test coverage for train_continuous()).

"train_continuous maintains class with `existing=NULL`,",
"and changes class to the class of `existing` when not NULL."
), {
expect_equal(
Copy link
Member

Choose a reason for hiding this comment

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

I think these can now fit on one line

@hadley hadley merged commit 2ccb2fb into r-lib:master Sep 7, 2018
@hadley
Copy link
Member

hadley commented Sep 7, 2018

Thanks!

hadley added a commit that referenced this pull request Nov 5, 2019
As it breaks ggforce and doesn't fix the motivating problem described in #166.
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