Skip to content

Commit

Permalink
Add exclamations (#294)
Browse files Browse the repository at this point in the history
* fix missing exclamations

* add tests

* test fixes

* more tests

* more tests

* add DataFrames dependency in docs

* Update Project.toml

* use jacob's yml snippet

* add news.md

Co-authored-by: Bogumił Kamiński <[email protected]>
  • Loading branch information
pdeffebach and bkamins authored Sep 8, 2021
1 parent baa306e commit 9b696ed
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-docdeploy@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
with:
version: '1.5'
version: '1.6'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# DataFramesMeta v0.9.1 Release notes

* Fix a bug with `@rtransform!` and `@rselect!`, where the macros were not actually mutating the data frame. ([#294](https://github.com/JuliaData/DataFramesMeta.jl/pull/294))

# DataFramesMeta v0.9.0 Release notes

* Add `@passmissing` flag for skipping missing values in row-wise macros. ([#272](https://github.com/JuliaData/DataFramesMeta.jl/pull/272))
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataFramesMeta"
uuid = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
version = "0.9.0"
version = "0.9.1"

[deps]
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Expand Down
6 changes: 3 additions & 3 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ end
Row-wise version of `@transform!`, i.e. all operations use `@byrow` by
default. See [`@transform!`](@ref) for details."""
macro rtransform!(x, args...)
esc(rtransform_helper(x, args...))
esc(rtransform!_helper(x, args...))
end

##############################################################################
Expand Down Expand Up @@ -1521,7 +1521,7 @@ function rselect!_helper(x, args...)

t = (fun_to_vec(ex; gensym_names=false, outer_flags=outer_flags) for ex in exprs)
quote
$DataFrames.select($x, $(t...))
$DataFrames.select!($x, $(t...))
end
end

Expand All @@ -1532,7 +1532,7 @@ Row-wise version of `@select!`, i.e. all operations use `@byrow` by
default. See [`@select!`](@ref) for details.
"""
macro rselect!(x, args...)
esc(rselect_helper(x, args...))
esc(rselect!_helper(x, args...))
end

##############################################################################
Expand Down
38 changes: 32 additions & 6 deletions test/byrow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,21 @@ end
@test @rtransform!(copy(df), :n = :g == 1 && :t == "a") @transform!(copy(df), :n = map((g, t) -> g == 1 && t == "a", :g, :t))
@test @rtransform!(copy(df), :n = first(:g)) @transform!(copy(df), :n = first.(:g))

d = @rtransform! df begin
df2 = copy(df)
d = @rtransform! df2 begin
:n1 = :i
:n2 = :i * :g
end
@test d === df2
@test d @transform!(copy(df), :n1 = :i, :n2 = :i .* :g)
@test d @transform!(copy(df), @byrow(:n1 = :i), @byrow(:n2 = :i * :g))

d = @rtransform! df begin
df2 = copy(df)
d = @rtransform! df2 begin
cols(:n1) = :i
:n2 = cols(:i) * :g
end
@test d === df2
@test d @transform!(copy(df), :n1 = :i, :n2 = :i .* :g)
d = @rtransform! df begin
:n1 = cols(:i)
Expand Down Expand Up @@ -352,17 +356,21 @@ end
@test @rselect!(copy(df), :n = :g == 1 && :t == "a") @select!(copy(df), :n = map((g, t) -> g == 1 && t == "a", :g, :t))
@test @rselect!(copy(df), :n = first(:g)) @select!(copy(df), :n = first.(:g))

d = @rselect! copy(df) begin
df2 = copy(df)
d = @rselect! df2 begin
:n1 = :i
:n2 = :i * :g
end
@test d === df2
@test d @select!(copy(df), :n1 = :i, :n2 = :i .* :g)
@test d @select!(copy(df), @byrow(:n1 = :i), @byrow(:n2 = :i * :g))

d = @rselect! copy(df) begin
df2 = copy(df)
d = @rselect! df2 begin
cols(:n1) = :i
:n2 = cols(:i) * :g
end
@test d === df2
@test d @select!(copy(df), :n1 = :i, :n2 = :i .* :g)
d = @rselect! copy(df) begin
:n1 = cols(:i)
Expand Down Expand Up @@ -437,10 +445,12 @@ end
@testset "@subset! with @byrow" begin
df = DataFrame(A = [1, 2, 3, missing], B = [2, 1, 2, 1])

d = @subset! copy(df) begin
df2 = copy(df)
d = @subset! df2 begin
@byrow :A > 1
@byrow :B > 1
end
@test d === df2
@test d @subset(df, :A .> 1, :B .> 1)

d = @subset! copy(df) @byrow begin
Expand All @@ -453,10 +463,12 @@ end
@testset "@rsubset!" begin
df = DataFrame(A = [1, 2, 3, missing], B = [2, 1, 2, 1])

d = @rsubset! copy(df) begin
df2 = copy(df)
d = @rsubset! df2 begin
:A > 1
:B > 1
end
@test d === df2
@test d @subset(df, :A .> 1, :B .> 1)

d = @rsubset! copy(df) begin
Expand Down Expand Up @@ -633,4 +645,18 @@ end
# no `@orderby!` for some reason.
end

@testset "row operations modify" begin
df = DataFrame(a = 1, b = 2)
cols = ["a", "b"]
for c in cols
@rtransform! df $c = $c + 100
end

@test df == DataFrame(a = 101, b = 102)

df = DataFrame(a = 1, b = 2)
@rselect! df :x = :a
@test names(df) == ["x"]
end

end

0 comments on commit 9b696ed

Please sign in to comment.