Skip to content

Conversation

@thisisnic
Copy link
Member

No description provided.

@github-actions
Copy link

@thisisnic thisisnic force-pushed the ARROW-12184-na.fail branch from 62be488 to d07dab6 Compare April 16, 2021 15:09
@thisisnic thisisnic marked this pull request as ready for review April 16, 2021 15:09
@@ -189,3 +187,109 @@ expect_vector_equal <- function(expr, # A vectorized R expression containing `in
skip(paste(skip_msg, collpase = "\n"))
}
}

expect_vector_equivalent <- function(expr, # A vectorized R expression containing `input` as its input
Copy link
Member

@ianmcook ianmcook Apr 19, 2021

Choose a reason for hiding this comment

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

I think it's worthwhile to have this new helper function, but it would be better to implement it by adding an optional argument ignore_attributes = FALSE to expect_vector_equal(), using that to control whether expect_equivalent() or expect_equal() is used, and then calling that function from this one. That would reduce the amount of copied code.

You'll need to use !! to unquote expr in the call to expect_vector_equivalent() from here.

Copy link
Member

Choose a reason for hiding this comment

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

(Please do push back if you think I'm mistaken about this or if I'm missing some important details!)

Copy link
Member

Choose a reason for hiding this comment

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

Another argument for expect_vector_equal(ignore_attributes = TRUE) is that testthat 3e deprecates expect_equivalent() in favor of expect_equal(ignore_attr = TRUE). And if we can name the argument, I would vote for ignore_attr over ignore_attributes to match testthat (well, I guess technically it's waldo at that point).

Copy link
Member

Choose a reason for hiding this comment

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

Agreed—best to name the attributeignore_attr 👍

Copy link
Member

Choose a reason for hiding this comment

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

Also heads up that expect_vector_equal() calls a function named expect_vector() but this is not testthat::expect_vector(); it's just a simple function defined higher up in helper-expectation.R. That confused me initially.

Copy link
Member

Choose a reason for hiding this comment

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

We can rename our expect_vector if that helps; I believe expect_vector is new in testthat (at least it's new to me).

Copy link
Member

Choose a reason for hiding this comment

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

➕ for renaming our expect_vector to avoid any possible confusion.

In other places I've been bitten by these testing helper name overlaps, and each time it's happened it threw me for a loop trying to figure out what was going wrong until I realized it was a name collision in a helper.

Copy link
Member Author

Choose a reason for hiding this comment

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

Have now updated the code here to implement ignore_attr. What makes sense as a new name for expect_vector? Maybe expect_as_vector or expect_vector_match?

Copy link
Member Author

Choose a reason for hiding this comment

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

Gone with expect_as_vector for now!

Copy link
Member

@jonkeane jonkeane left a comment

Choose a reason for hiding this comment

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

This is looking good. Most of my comments are super minor whitespace things. But two more substantive comments.

na.omit.ArrowTabular <- function(object, ...){

na_expr <- paste0("!is.na(", names(object), ")", collapse = ",")
filter_expr <- paste0("dplyr::filter(object,", na_expr, ")")
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to implement this without dplyr? We only suggest dplyr, and it would be nice to not have to have it installed/loaded for na.omit() to work. This might not be the right approach, but my first thought: would it be possible to iterate objects and use the na.omit() method above? (or use the $Filter method you use above)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, didn't realise it was only a suggest; I'll have a think!

Copy link
Member Author

Choose a reason for hiding this comment

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

Refactored now!

@@ -189,3 +187,109 @@ expect_vector_equal <- function(expr, # A vectorized R expression containing `in
skip(paste(skip_msg, collpase = "\n"))
}
}

expect_vector_equivalent <- function(expr, # A vectorized R expression containing `input` as its input
Copy link
Member

Choose a reason for hiding this comment

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

Another argument for expect_vector_equal(ignore_attributes = TRUE) is that testthat 3e deprecates expect_equivalent() in favor of expect_equal(ignore_attr = TRUE). And if we can name the argument, I would vote for ignore_attr over ignore_attributes to match testthat (well, I guess technically it's waldo at that point).

@thisisnic thisisnic force-pushed the ARROW-12184-na.fail branch from 8730001 to 2b5bc7a Compare April 20, 2021 09:41
Copy link
Member

@nealrichardson nealrichardson left a comment

Choose a reason for hiding this comment

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

Overall this looks great. Two suggestions for how I think it can be even better, but not hugely important.

thisisnic and others added 4 commits April 21, 2021 16:23
Co-authored-by: Neal Richardson <neal.p.richardson@gmail.com>
Co-authored-by: Neal Richardson <neal.p.richardson@gmail.com>
@thisisnic thisisnic force-pushed the ARROW-12184-na.fail branch from 35f9b22 to f113284 Compare April 21, 2021 15:23
Copy link
Member

@nealrichardson nealrichardson left a comment

Choose a reason for hiding this comment

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

Very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants