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.
Summary
This PR adds relevant tests for the
@slice()
macro based on the tests which are in the dplyr code, found here. I skipped quite a few tests that involve functionality that I don't think is implemented yet. I also didn't go crazy and add all the possible tests to keep the PR at a reasonable size for review.I went ahead and put these under the
tests/
folder rather than implementing as doctests. My thinking on this is that there are two types of things that I can foresee wanting to test:This keeps the documentation examples concise and helpful while also thoroughly testing the underlying functionality in various scenarios. I think most if not all of these tests fall under the second case.
Overview of the Implemented Tests
The test summary currently looks like this:
I'll drop some descriptions of the failing tests below for discussion😄
Positive Indices Test
Here's the R code and output from the test I'm trying to replicate:
Here's what happens in Julia:
Negative Indices Test
Same for the negative indices, here's the R code:
Here's the Julia code and resulting error (it's very similar to the one above)
I suspect that these are failing because
GroupedDataFrames
don't behave quite the same as a groupedtibble
does in R as far as things like indexing go, so I'm curious if this is a place where we'd expect theTidier
equivalent ofdplyr
code to behave exactly the same.Zero-Length Groups
This is an interesting set of tests. Basically the gist is that in
dplyr
, if one of the grouping variables is a factor with defined levels,slice()
should still retain this group when working with a grouped data frame. This is mostly for consistency/expected results when working with grouped data in R.There isn't a
group_size
function in Julia, so I tried to get the size of each group for comparison withcombine
andnrow
. The zero-length group doesn't seem to be accounted for, so this test fails as the size vector is of length 2 rather than one of length 3 that looks like[1, 1, 0]
as it does in the R test.That being said - this may not be a
slice()
issue, as theGroupedDataFrame
itself seems to only have 2 groups and doesn't appear to account for the zero-length group even though it seems to recognize that there is one.So this may be a case where we really don't expect the same behavior because
DataFrames
doesn't behave the same as R--and if so we could probably just drop these two testsets.