Skip to content

Commit 960138b

Browse files
committed
Update GroupedArrays.jl
1 parent 7616d76 commit 960138b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/GroupedArrays.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,31 @@ Base.axes(g::GroupedArray) = axes(g.refs)
1313
Base.IndexStyle(g::GroupedArray) = Base.IndexLinear()
1414
Base.LinearIndices(g::GroupedArray) = axes(g.refs, 1)
1515

16+
Base.@propagate_inbounds function Base.getindex(g::GroupedArray{Int}, i::Number)
17+
@boundscheck checkbounds(g, i)
18+
@inbounds g.refs[i]
19+
end
1620

1721
Base.@propagate_inbounds function Base.getindex(g::GroupedArray, i::Number)
1822
@boundscheck checkbounds(g, i)
1923
@inbounds x = g.refs[i]
2024
x == 0 ? missing : x
2125
end
22-
Base.@propagate_inbounds function Base.getindex(g::GroupedArray{Int}, i::Number)
23-
@boundscheck checkbounds(g, i)
24-
@inbounds g.refs[i]
25-
end
2626

2727
Base.@propagate_inbounds function Base.setindex!(g::GroupedArray, x::Number, i::Number)
2828
@boundscheck checkbounds(g, i)
29-
x <= 0 && throw(ArgumentError("The number x must be positive"))
30-
x > g.ngroups && (g.ngroups = x)
29+
x > 0 || throw(ArgumentError("The number x must be positive"))
30+
if x > g.ngroups
31+
g.ngroups = x
32+
end
3133
@inbounds g.refs[i] = x
3234
end
3335

36+
Base.@propagate_inbounds function Base.setindex!(g::GroupedArray{T}, x::Missing, i::Number) where {T >: Missing}
37+
@boundscheck checkbounds(g, i)
38+
@inbounds g.refs[i] = 0
39+
end
40+
3441
# Constructor
3542
function GroupedArray(args...; coalesce = false)
3643
s = size(args[1])

0 commit comments

Comments
 (0)