diff --git a/src/processes.jl b/src/processes.jl index 8b554a0984..c044c5d777 100644 --- a/src/processes.jl +++ b/src/processes.jl @@ -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) diff --git a/test/Project.toml b/test/Project.toml index 63a8df7170..dbe2b76b1d 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -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" diff --git a/test/preamble.jl b/test/preamble.jl index 52f18bc50d..02ec8aef10 100644 --- a/test/preamble.jl +++ b/test/preamble.jl @@ -1,3 +1,4 @@ +using Compat: eachrow using Test using Random using SparseArrays: issparse, sparse diff --git a/test/test_copy.jl b/test/test_copy.jl index 9919144e5b..c7d667cafc 100644 --- a/test/test_copy.jl +++ b/test/test_copy.jl @@ -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