Skip to content

Commit

Permalink
Test and document copy(xf, eachrow(df))
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Dec 16, 2019
1 parent fdc6842 commit f0d2fee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,18 @@ julia> using StructArrays
julia> @assert copy(Map(x -> (a=x, b=x^2)), StructVector, 1:1) == StructVector(a=[1], b=[1])
```
As `DataFrame` does not have iteration interface yet, use `eachrow` to
process rows of a dataframe. Note that `copy` automatically use
`DataFrame` as default output type in this case:
```jldoctest; setup = :(using Transducers)
julia> using DataFrames
julia> @assert copy(
Map(x -> (A = x.a + 1, B = x.b + 1)),
eachrow(DataFrame(a = [1], b = [2])),
) == DataFrame(A = [2], B = [3])
"""
Base.copy(xf::Transducer, ::Type{T}, foldable) where {T} = append!!(xf, Empty(T), foldable)
Base.copy(xf::Transducer, foldable) = copy(xf, _materializer(foldable), foldable)
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
1 change: 1 addition & 0 deletions test/preamble.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Compat: eachrow
using Test
using Random
using SparseArrays: issparse, sparse
Expand Down
3 changes: 1 addition & 2 deletions test/test_copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ end
end
@testset "$copy(_, eachrow(df))" begin
df = DataFrame(a=[1], b=[2])
@test_broken copy(Map(identity), eachrow(df)) ==ₜ df
# requires https://github.com/JuliaData/DataFrames.jl/pull/2055
@test copy(Map(identity), eachrow(df)) ==ₜ df
end
end

Expand Down

0 comments on commit f0d2fee

Please sign in to comment.