Skip to content

Commit

Permalink
AbstractRange can be aliased
Browse files Browse the repository at this point in the history
  • Loading branch information
gustafsson committed Oct 25, 2022
1 parent c07ab6e commit d681f96
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions test/alias.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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)
Expand Down
12 changes: 7 additions & 5 deletions test/grouping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d681f96

Please sign in to comment.