Skip to content

Commit 7616d76

Browse files
committed
update
1 parent 688d3a5 commit 7616d76

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ g = GroupedArray(p1, p2)
4949
# 3
5050
```
5151
## Motivation
52-
Internally, a `GroupedArray` is stored as a vector of Integers, where 0 corresponds to `missing`.
53-
54-
GroupedArrays can be seen as a PooledDataArray restricted to integers (+ missing). This has two advantages. First, there is no need to carry arround a vector of pooled values. Second, it makes it straightforward to define a constructor that takes multiple vectors as arguments.
52+
GroupedArrays can be seen as a PooledDataArray where the reference number gives the value (except that 0 corresponds to `missing`). This allows one to make lookup faster when the group value is not meaningful.
5553

5654
## See also
5755
The algorithm to construct `GroupedArrays` is taken from [DataFrames.jl](https://github.com/JuliaData/DataFrames.jl)

src/GroupedArrays.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ 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+
1617
Base.@propagate_inbounds function Base.getindex(g::GroupedArray, i::Number)
1718
@boundscheck checkbounds(g, i)
1819
@inbounds x = g.refs[i]
1920
x == 0 ? missing : x
2021
end
21-
Base.@propagate_inbounds function Base.setindex!(g::GroupedArray{T}, x::Missing, i::Number) where T >: Missing
22+
Base.@propagate_inbounds function Base.getindex(g::GroupedArray{Int}, i::Number)
2223
@boundscheck checkbounds(g, i)
23-
@inbounds g.refs[i] = 0
24+
@inbounds g.refs[i]
2425
end
26+
2527
Base.@propagate_inbounds function Base.setindex!(g::GroupedArray, x::Number, i::Number)
2628
@boundscheck checkbounds(g, i)
2729
x <= 0 && throw(ArgumentError("The number x must be positive"))
@@ -60,7 +62,7 @@ Base.axes(x::GroupedRefPool{T}) where T = ((1-(T >: Missing)):x.ngroups,)
6062
Base.IndexStyle(::Type{<: GroupedRefPool}) = Base.IndexLinear()
6163
Base.@propagate_inbounds function Base.getindex(x::GroupedRefPool{T}, i::Integer) where T
6264
@boundscheck checkbounds(x, i)
63-
if T >: Missing && (i==0)
65+
if (T >: Missing) && (i==0)
6466
return missing
6567
else
6668
i

0 commit comments

Comments
 (0)