Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix repeat and some other minor issues #2648

Merged
merged 4 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1676,10 +1676,10 @@ julia> repeat(df, inner = 2, outer = 3)
12 │ 2 4
```
"""
function Base.repeat(df::AbstractDataFrame; inner::Integer = 1, outer::Integer = 1)
function Base.repeat(df::AbstractDataFrame; inner::Integer=1, outer::Integer=1)
inner < 0 && throw(ArgumentError("inner keyword argument must be non-negative"))
outer < 0 && throw(ArgumentError("outer keyword argument must be non-negative"))
return mapcols(x -> repeat(x, inner = inner, outer = outer), df)
return mapcols(x -> repeat(x, inner = Int(inner), outer = Int(outer)), df)
end

"""
Expand Down Expand Up @@ -1711,7 +1711,7 @@ julia> repeat(df, 2)
"""
function Base.repeat(df::AbstractDataFrame, count::Integer)
count < 0 && throw(ArgumentError("count must be non-negative"))
return mapcols(x -> repeat(x, count), df)
return mapcols(x -> repeat(x, Int(count)), df)
end

##############################################################################
Expand Down
4 changes: 2 additions & 2 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ julia> df
function repeat!(df::DataFrame; inner::Integer = 1, outer::Integer = 1)
inner < 0 && throw(ArgumentError("inner keyword argument must be non-negative"))
outer < 0 && throw(ArgumentError("outer keyword argument must be non-negative"))
return mapcols!(x -> repeat(x, inner = inner, outer = outer), df)
return mapcols!(x -> repeat(x, inner = Int(inner), outer = Int(outer)), df)
end

"""
Expand Down Expand Up @@ -1648,7 +1648,7 @@ julia> repeat(df, 2)
"""
function repeat!(df::DataFrame, count::Integer)
count < 0 && throw(ArgumentError("count must be non-negative"))
return mapcols!(x -> repeat(x, count), df)
return mapcols!(x -> repeat(x, Int(count)), df)
end

# This is not exactly copy! as in general we allow axes to be different
Expand Down
2 changes: 1 addition & 1 deletion test/broadcasting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ end
@test levels(df.c4) == levels(v)
@test levels(df.c4) !== levels(v)
df[!, :c5] .= (x->v[2]).(v)
@test unique(df.c5) == [get(v[2])]
@test unique(df.c5) == [unwrap(v[2])]
@test df.c5 isa CategoricalVector
@test levels(df.c5) == levels(v)
end
Expand Down
8 changes: 6 additions & 2 deletions test/subdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,12 @@ end
@test_throws ArgumentError SubDataFrame(sdf, true, :)
@test_throws ArgumentError SubDataFrame(sdf, Integer[true], 1)

# this is an error in Julia Base
SubDataFrame(sdf, Integer[true, true, true], :) == SubDataFrame(sdf, [1, 1, 1], :)
if VERSION > v"1.6"
@test_throws ArgumentError SubDataFrame(sdf, Integer[true, true, true], :)
else
@test SubDataFrame(sdf, Integer[true, true, true], :) ==
SubDataFrame(sdf, [1, 1, 1], :)
end
end

end # module
1 change: 0 additions & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ end
@test size(repeat(df, inner = 0, outer = 3)) == (0, 2)
@test size(repeat(df, inner = 2, outer = false)) == (0, 2)
@test size(repeat(df, inner = false, outer = 3)) == (0, 2)

@test_throws ArgumentError repeat(df, inner = 2, outer = -1)
@test_throws ArgumentError repeat(df, inner = -1, outer = 3)
end
Expand Down