Skip to content

Commit

Permalink
Merge pull request #99 from TidierOrg/fix-distinct-multiple-columns
Browse files Browse the repository at this point in the history
Bug fix to allow multiple columns to `@distinct()`. Bumped version to 0.7.6.
  • Loading branch information
Karandeep Singh authored May 5, 2023
2 parents 061d827 + 05e539a commit fdce992
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Tidier.jl updates

## v0.7.6 - 2023-05-04
- Fixed bug to allow multiple columns in `@distinct()` separated by commas or using selection helpers.

## v0.7.5 - 2023-04-30
- Fixed bug to ensure that `&&` and `||` are auto-vectorized
- Added docstrings and examples to show different ways of filtering by multiple "and" conditions, including `&&`, `&`, and separating multiple expressions with commas.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Tidier"
uuid = "f0413319-3358-4bb0-8e7c-0c83523a93bd"
authors = ["Karandeep Singh"]
version = "0.7.5"
version = "0.7.6"

[deps]
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
Expand Down
16 changes: 14 additions & 2 deletions src/Tidier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,13 @@ macro distinct(df, exprs...)
_
end
end
unique($(tidy_exprs...))
@chain _ begin
if length([$tidy_exprs...]) == 0
unique(_)
else
unique(_, Cols($(tidy_exprs...)))
end
end
select(Cols(Not(r"^(Tidier_n|Tidier_row_number)$")))
groupby(col_names; sort = true) # regroup
end
Expand All @@ -587,7 +593,13 @@ macro distinct(df, exprs...)
_
end
end
unique($(tidy_exprs...))
@chain _ begin
if length([$tidy_exprs...]) == 0
unique(_)
else
unique(_, Cols($(tidy_exprs...)))
end
end
select(Cols(Not(r"^(Tidier_n|Tidier_row_number)$")))
end
end
Expand Down
47 changes: 39 additions & 8 deletions src/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ If no columns or expressions are provided, then unique rows across all columns a
# Examples
```jldoctest
julia> df = DataFrame(a = repeat('a':'e', inner = 2), b = 1:10, c = 11:20);
julia> df = DataFrame(a = repeat('a':'e', inner = 2), b = repeat(1:5, 2), c = 11:20);
julia> @chain df begin
@distinct()
Expand All @@ -726,11 +726,11 @@ julia> @chain df begin
3 │ b 3 13
4 │ b 4 14
5 │ c 5 15
6 │ c 6 16
7 │ d 7 17
8 │ d 8 18
9 │ e 9 19
10 │ e 10 20
6 │ c 1 16
7 │ d 2 17
8 │ d 3 18
9 │ e 4 19
10 │ e 5 20
julia> @chain df begin
@distinct(a)
Expand All @@ -742,8 +742,39 @@ julia> @chain df begin
1 │ a 1 11
2 │ b 3 13
3 │ c 5 15
4 │ d 7 17
5 │ e 9 19
4 │ d 2 17
5 │ e 4 19
julia> @chain df begin
@distinct(starts_with("a"))
end
5×3 DataFrame
Row │ a b c
│ Char Int64 Int64
─────┼────────────────────
1 │ a 1 11
2 │ b 3 13
3 │ c 5 15
4 │ d 2 17
5 │ e 4 19
julia> @chain df begin
@distinct(a, b)
end
10×3 DataFrame
Row │ a b c
│ Char Int64 Int64
─────┼────────────────────
1 │ a 1 11
2 │ a 2 12
3 │ b 3 13
4 │ b 4 14
5 │ c 5 15
6 │ c 1 16
7 │ d 2 17
8 │ d 3 18
9 │ e 4 19
10 │ e 5 20
```
"""

Expand Down

2 comments on commit fdce992

@kdpsingh
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/82947

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.6 -m "<description of version>" fdce9922113a1ba4f707d731a2361f9597e668ef
git push origin v0.7.6

Please sign in to comment.