TidierOrg / TidierData.jl

Tidier data transformations in Julia, modeled after the dplyr/tidyr R packages.
MIT License
86 stars 7 forks source link

Unexpected interaction between @slice and @group_by #68

Closed rdboyes closed 10 months ago

rdboyes commented 10 months ago

The slice macro interacts differently with @group_by depending on whether you use positive or negative selection in slice.

@chain DataFrame(a = [1,2,3,4], b = ["a", "a", "b", "b"]) begin
    @group_by(b)
    @slice(1)
end

Produces the expected result:

GroupedDataFrame with 2 groups based on key: b
First Group (1 row): b = "a"
 Row │ b       a     
     │ String  Int64
─────┼───────────────
   1 │ a           1
⋮
Last Group (1 row): b = "b"
 Row │ b       a     
     │ String  Int64
─────┼───────────────
   1 │ b           3

While the negative version, which should be equivalent:

@chain DataFrame(a = [1,2,3,4], b = ["a", "a", "b", "b"]) begin
    @group_by(b)
    @slice(-2)
end

Ungroups the data, giving:

2×2 DataFrame
 Row │ b       a     
     │ String  Int64
─────┼───────────────
   1 │ a           1
   2 │ b           3
kdpsingh commented 10 months ago

This is probably my fault. When @drizk1 fixed a bug in the behavior of n() inside of @slice(), I messed with some of the grouping mechanics in his code. I fixed one issue but may have missed or caused this one. Should be easy to fix.

drizk1 commented 10 months ago

Also entirely possible that I introduced this bug as well. I'm happy to take a look at it.

rdboyes commented 10 months ago

I updated to the development version and this seems to be fixed! Sorry for the fake bug report/thanks for fixing this, depending on whether you updated it recently

kdpsingh commented 10 months ago

The current developmental version should match the latest release version. I think I may have fixed this issue in the last couple of versions when I was going through @drizk1's PR. I'll confirm on my end if it works and will close the issue after I confirm.

kdpsingh commented 10 months ago

Just confirmed that it works correctly.