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 1a6fe2b commit e9d0c27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 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
5 changes: 2 additions & 3 deletions test/test_copy.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TestCopy

include("preamble.jl")
using DataFrames: DataFrame
using DataFrames: DataFrame, eachrow
using StructArrays: StructVector
using TypedTables: Table

Expand All @@ -25,8 +25,7 @@ end
end
@testset "$copy(_, eachrow(df))" begin
df = DataFrame(a=[1:4;], b=[5:8;])
@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 e9d0c27

Please sign in to comment.