Skip to content

Commit 1045445

Browse files
authored
bug fix - combine/modify with vec{vec} input (#99)
1 parent d3feeef commit 1045445

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Fix issue with `QuickSortAlg` in future version of Julia
66
* Empty the rows of a `SubDataset` without columns
7+
* Fix a bug which causes `modify/combine` throw errors on columns with Vector{Vector} type
78

89
# Version 0.7.12
910

src/other/utils.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ end
3030
# modified return_type to suit for our purpose
3131
function return_type(f::Function, x)
3232
eltype(x) == Missing && return Missing
33-
CT = nonmissingtype(eltype(x))
34-
if CT <: AbstractVector
33+
34+
if eltype(x) <: AbstractVector
3535
return return_type_tuple(f, x)
3636
end
37+
CT = nonmissingtype(eltype(x))
3738
T = Core.Compiler.return_type(f, Tuple{Vector{CT}})
3839
# workaround for SubArray type
3940
if T <: SubArray

test/grouping.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,21 @@ end
642642
@test ds == Dataset(x1 = [1,2,1,2], x2 = [1,-2,-3,10], x3 = 1:4, z = [1.0, missing, -1.0, missing])
643643

644644
end
645+
646+
@testset "combine and modify with Vector{Vector}" begin
647+
ds = Dataset(x=[[1,2],[2,3]])
648+
@test modify(ds, :x=>length=>:y) == Dataset(x=[[1,2],[2,3]], y=2)
649+
@test combine(ds, :x=>sum) == Dataset(sum_x=[3,5])
650+
651+
ds = Dataset(x=[[1.0,2.0,missing],[2.0,3.0,1.0]])
652+
@test modify(ds, :x=>length=>:y) == Dataset(x=[[1.0,2.0,missing],[2.0,3.0,1.0]], y=2)
653+
@test combine(ds, :x=>(x->sum(x)::Vector{Union{Float64, Missing}})) == Dataset(function_x=[3.0,5.0,missing])
654+
655+
function _f_12345667(x, y)
656+
map(z->z[1], x) .+ y
657+
end
658+
659+
ds = Dataset(x=[[1,2],[2,3]], y=2)
660+
@test modify(ds, (:x,:y)=>_f_12345667) == Dataset(x=[[1,2],[2,3]], y=2,_f_12345667_x_y = [3,4])
661+
662+
end

0 commit comments

Comments
 (0)