From 9d87bcf42411a18219f0529456b8286b6284ba62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Wed, 10 Mar 2021 18:58:20 +0100 Subject: [PATCH] fix repeat and some other minor issues (#2648) --- src/abstractdataframe/abstractdataframe.jl | 6 +++--- src/dataframe/dataframe.jl | 4 ++-- test/broadcasting.jl | 2 +- test/subdataframe.jl | 8 ++++++-- test/utils.jl | 1 - 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index df21c74683..d1d6e0a219 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -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 """ @@ -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 ############################################################################## diff --git a/src/dataframe/dataframe.jl b/src/dataframe/dataframe.jl index 6b19a51f83..023494d9ba 100644 --- a/src/dataframe/dataframe.jl +++ b/src/dataframe/dataframe.jl @@ -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 """ @@ -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 diff --git a/test/broadcasting.jl b/test/broadcasting.jl index d19f22950c..b4baf252c8 100644 --- a/test/broadcasting.jl +++ b/test/broadcasting.jl @@ -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 diff --git a/test/subdataframe.jl b/test/subdataframe.jl index 8deec0e51d..cc9ce19344 100644 --- a/test/subdataframe.jl +++ b/test/subdataframe.jl @@ -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 diff --git a/test/utils.jl b/test/utils.jl index 5dd3a64623..0db4577030 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -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