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

Improve list_simplify() performance + errors #942

Merged
merged 7 commits into from
Sep 15, 2022
Merged

Conversation

hadley
Copy link
Member

@hadley hadley commented Sep 14, 2022

Fixes #935

@hadley hadley requested a review from DavisVaughan September 14, 2022 20:37
@hadley
Copy link
Member Author

hadley commented Sep 14, 2022

Oooh, and name management from https://github.com/tidyverse/purrr/pull/894/files#r957388812.

Comment on lines 90 to 91
x <- vec_set_names(x, NULL)
out <- list_unchop(x, ptype = ptype)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I think this is slightly wrong because if the unchop fails and strict = FALSE, then we will return x which might have had its names stripped by this

Test for this case is probably useful, something like "returns a named list when input is named and simplification fails"

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops yes. Let me refactor.

@@ -83,8 +101,12 @@ simplify_impl <- function(x,
)
} else {
if (strict) {
bad <- detect_index(x, function(x) vec_size(x) != 1)
Copy link
Member

Choose a reason for hiding this comment

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

You could also do

which(list_sizes(x) != 1L)[[1L]]

or store the result of list_sizes(x) == 1L as where_size_one from when you computed it above in the strict branch along with the list_check_all_vectors() check, and then reference it here like bad <- which(!where_size_one)[[1L]]

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this error up into the earlier strict branch which I think makes it easier to follow.

Copy link
Member

@DavisVaughan DavisVaughan left a comment

Choose a reason for hiding this comment

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

Looks great now!

@hadley hadley merged commit d42413f into main Sep 15, 2022
@hadley hadley deleted the list-simplify-perf-errors branch September 15, 2022 14:26
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.

Reconsider can_simplify() in list_simplify()
2 participants