diff --git a/src/dataframe/dataframe.jl b/src/dataframe/dataframe.jl index d3b45e3294..941a9dd113 100755 --- a/src/dataframe/dataframe.jl +++ b/src/dataframe/dataframe.jl @@ -232,7 +232,7 @@ end function _preprocess_column(col::Any, len::Integer, copycols::Bool) if col isa AbstractRange - return collect(col) + return copycols ? collect(col) : col elseif col isa AbstractVector return copycols ? copy(col) : col elseif col isa Union{AbstractArray{<:Any, 0}, Ref} diff --git a/test/alias.jl b/test/alias.jl index bf18e4618d..1e89efbc56 100644 --- a/test/alias.jl +++ b/test/alias.jl @@ -9,6 +9,7 @@ const ≅ = isequal dfr = DataFrame(init, :auto) @testset "$v" for v in [ [1,2,3], + 1:3, ] @testset "df.x2 = v" begin df = copy(dfr) diff --git a/test/grouping.jl b/test/grouping.jl index d26f09cb22..a6336a96d2 100644 --- a/test/grouping.jl +++ b/test/grouping.jl @@ -4171,7 +4171,7 @@ end # eachindex on DataFrame @test combine(df, eachindex) == DataFrame(eachindex=1:6) @test isequal_coltyped(combine(DataFrame(), eachindex), - DataFrame(eachindex=Int[])) + DataFrame(eachindex=Base.OneTo(0), copycols = false)) # Disallowed operations @test_throws ArgumentError groupindices(df) @@ -4248,14 +4248,16 @@ end DataFrame(x = df.x, id = df.id, eachindex = 1:6) df = view(df, [], :) df2 = combine(df, eachindex) - @test isequal_coltyped(df2, DataFrame(eachindex = Int[])) + @test isequal_coltyped(df2, DataFrame(eachindex = Base.OneTo(0), copycols = false)) @test isequal_coltyped(df2, combine(eachindex, df)) - @test isequal_coltyped(df2, rename(combine(df, eachindex => :a), :a => :eachindex)) + @test isequal_coltyped(df2, rename!(combine(df, eachindex => :a), :a => :eachindex)) + @test isequal_coltyped(copy(df2), rename(combine(df, eachindex => :a), :a => :eachindex)) df2 = transform(df, eachindex) - @test isequal_coltyped(df2, DataFrame(x = Int[], id = Int[], eachindex = Int[])) + @test isequal_coltyped(df2, DataFrame(x = Int[], id = Int[], eachindex = Base.OneTo(0), copycols = false)) @test isequal_coltyped(df2, transform(eachindex, df)) - @test isequal_coltyped(df2, rename(transform(df, eachindex => :a), :a => :eachindex)) + @test isequal_coltyped(df2, rename!(transform(df, eachindex => :a), :a => :eachindex)) + @test isequal_coltyped(copy(df2), rename(transform(df, eachindex => :a), :a => :eachindex)) end @testset "fillfirst! correctness tests" begin diff --git a/test/iteration.jl b/test/iteration.jl index cbd6f5f146..678d581a02 100644 --- a/test/iteration.jl +++ b/test/iteration.jl @@ -73,7 +73,7 @@ end df = DataFrame(a=1) df = mapcols(x -> 2:2, df) @test df == DataFrame(a=2) - @test df.a isa Vector{Int} + @test df.a isa AbstractRange{Int} end @testset "mapcols!" begin