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

Add tests for behavior of count() #6904

Merged
merged 3 commits into from
Aug 23, 2023
Merged

Add tests for behavior of count() #6904

merged 3 commits into from
Aug 23, 2023

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Aug 4, 2023

None of the existing tests was triggered when the sort order wasn't established.

I see that summarize(.by = ...) has a different default (of returning in the order of appearance), I wonder what the long-term intention for count() is.

@DavisVaughan
Copy link
Member

I think it is sort of reasonable to say that the sort order of count() is undefined unless you set sort = TRUE to sort by count size, so we may be able to change it in the future.

See also #6806 where I think the long term data.frame implementation of count/tally would use vec_count() to make it much faster, but that is tough because count() has proven to be fairly complicated.

Comment on lines +17 to +18
out <- count(df, y = x)
expect_equal(out, tibble(y = c(1, 2), n = c(3, 2)))
Copy link
Member

Choose a reason for hiding this comment

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

😬 I didn't even know this worked and I'm not sure I like it

Copy link
Member Author

@krlmlr krlmlr Aug 23, 2023

Choose a reason for hiding this comment

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

There might be a CRAN package that uses this feature.

@krlmlr
Copy link
Member Author

krlmlr commented Aug 23, 2023

A random sort order means that count() behaves somewhat differently from summarize(), though. I don't have a strong opinion, we can leave it open for now.

@krlmlr krlmlr marked this pull request as draft August 23, 2023 13:53
@DavisVaughan
Copy link
Member

I'm happy to merge this one as is, I do agree we should at least test it so if we ever change things in the future it forces us to acknowledge that we are breaking something

@DavisVaughan DavisVaughan marked this pull request as ready for review August 23, 2023 13:55
@DavisVaughan DavisVaughan merged commit 41501e4 into main Aug 23, 2023
11 checks passed
@DavisVaughan DavisVaughan deleted the f-count-sort branch August 23, 2023 13:55
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.

2 participants