Skip to content

Commit 537c916

Browse files
committed
fix #51
1 parent 1313086 commit 537c916

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/byrow/row_functions.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ function row_sum(ds::AbstractDataset, f::Function, cols = names(ds, Union{Missi
3333
colsidx = multiple_getindex(index(ds), cols)
3434
CT = mapreduce(eltype, promote_type, view(_columns(ds),colsidx))
3535
T = Core.Compiler.return_type(f, Tuple{CT})
36+
CT = nonmissingtype(T)
37+
CT <: Base.SmallSigned ? CT = Int : nothing
38+
CT <: Base.SmallUnsigned ? CT = UInt : nothing
39+
CT <: Bool ? CT = Int : nothing
40+
T = Union{Missing, CT}
3641
init0 = _missings(T, nrow(ds))
3742

3843
if threads
@@ -63,6 +68,11 @@ function row_prod(ds::AbstractDataset, f::Function, cols = names(ds, Union{Missi
6368
colsidx = multiple_getindex(index(ds), cols)
6469
CT = mapreduce(eltype, promote_type, view(_columns(ds),colsidx))
6570
T = Core.Compiler.return_type(f, Tuple{CT})
71+
CT = nonmissingtype(T)
72+
CT <: Base.SmallSigned ? CT = Int : nothing
73+
CT <: Base.SmallUnsigned ? CT = UInt : nothing
74+
CT <: Bool ? CT = Int : nothing
75+
T = Union{Missing, CT}
6676
init0 = _missings(T, nrow(ds))
6777

6878
if threads

test/byrow.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@
341341
@test byrow(ds, join, :) == ["α111.4", "β∘125.6"]
342342
@test byrow(ds, join, :, delim = ",") == ["α1,1,1.4", "β∘1,2,5.6"]
343343
@test byrow(ds, join, :, delim = ":×:") == ["α1:×:1:×:1.4", "β∘1:×:2:×:5.6"]
344+
345+
346+
# promoting small ints
347+
ds = Dataset(x1=Int8[127,127],x2=Int8[127,-127])
348+
@test byrow(ds,sum) == [254,0]
349+
@test byrow(ds,prod) == [16129,-16129]
350+
ds = Dataset(x1=[true,true,false],x2=[true,true,false],x3=[true,false,true])
351+
@test byrow(ds,sum)==[3,2,1]
344352
end
345353

346354
@testset "cum*/! - sort/!" begin

0 commit comments

Comments
 (0)