Skip to content

Commit 77931af

Browse files
committed
rename to groups
1 parent c45f78a commit 77931af

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GroupedArrays"
22
uuid = "6407cd72-fade-4a84-8a1e-56e431fc1533"
33
authors = ["matthieugomez <gomez.matthieu@gmail.com>"]
4-
version = "0.2.2"
4+
version = "0.3.0"
55

66
[deps]
77
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"

src/GroupedArrays.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,43 @@ using Base.Threads
55
include("spawn.jl")
66
include("utils.jl")
77
mutable struct GroupedArray{T <: Union{Int, Missing}, N} <: AbstractArray{T, N}
8-
refs::Array{Int, N} # refs must be between 0 and n. 0 means missing
9-
ngroups::Int # Number of potential values (as a contract, we always have ngroups >= maximum(refs))
8+
groups::Array{Int, N} # groups must be between 0 and n. 0 means missing
9+
ngroups::Int # Number of potential values (as a contract, we always have ngroups >= maximum(groups))
1010
end
1111
const GroupedVector{T} = GroupedArray{T, 1}
1212
const GroupedMatrix{T} = GroupedArray{T, 2}
1313

14-
Base.size(g::GroupedArray) = size(g.refs)
15-
Base.axes(g::GroupedArray) = axes(g.refs)
14+
Base.size(g::GroupedArray) = size(g.groups)
15+
Base.axes(g::GroupedArray) = axes(g.groups)
1616
Base.IndexStyle(g::GroupedArray) = Base.IndexLinear()
17-
Base.LinearIndices(g::GroupedArray) = axes(g.refs, 1)
17+
Base.LinearIndices(g::GroupedArray) = axes(g.groups, 1)
1818

1919
Base.@propagate_inbounds function Base.getindex(g::GroupedArray{Int}, i::Number)
2020
@boundscheck checkbounds(g, i)
21-
@inbounds g.refs[i]
21+
@inbounds g.groups[i]
2222
end
2323

2424
Base.@propagate_inbounds function Base.getindex(g::GroupedArray, i::Number)
2525
@boundscheck checkbounds(g, i)
26-
@inbounds x = g.refs[i]
26+
@inbounds x = g.groups[i]
2727
x == 0 ? missing : x
2828
end
2929

3030
Base.@propagate_inbounds function Base.setindex!(g::GroupedArray, x::Number, i::Number)
3131
@boundscheck checkbounds(g, i)
3232
x > 0 || throw(ArgumentError("The number x must be positive"))
3333
x > g.ngroups && (g.ngroups = x)
34-
@inbounds g.refs[i] = x
34+
@inbounds g.groups[i] = x
3535
end
3636

3737
Base.@propagate_inbounds function Base.setindex!(g::GroupedArray{T}, ::Missing, i::Number) where {T >: Missing}
3838
@boundscheck checkbounds(g, i)
39-
@inbounds g.refs[i] = 0
39+
@inbounds g.groups[i] = 0
4040
end
4141
"""
4242
Constructor for GroupedArrays
4343
44-
GroupedArray constructor always promises that all elements between 1 and ngroups (included) are presented in refs. However, this is not necessarly true aftewards (setindex! does not check that the replaced ref corresponds to the last one)
44+
GroupedArray constructor always promises that all elements between 1 and ngroups (included) are presented in groups. However, this is not necessarly true aftewards (setindex! does not check that the replaced ref corresponds to the last one)
4545
4646
if coalesce = true, missing values are associated an integer
4747
if sort = false, groups are created in order of appearances. If sort = true, groups are sorted. If sort = nothing, fastest algorithm is used.
@@ -53,7 +53,7 @@ function GroupedArray(args...; coalesce = false, sort = nothing)
5353
ngroups, rhashes, gslots, sorted = row_group_slots(vec.(args), Val(false), groups, !coalesce, sort)
5454
# sort groups if row_group_slots hasn't already done that
5555
if sort === true && !sorted
56-
idx = find_index(GroupedArray{Int, 1}(groups, ngroups))
56+
idx = find_index(GroupedVector{Int}(groups, ngroups))
5757
group_invperm = invperm(sortperm(collect(zip(map(x -> view(x, idx), args)...))))
5858
@inbounds for (i, gix) in enumerate(groups)
5959
groups[i] = gix > 0 ? group_invperm[gix] : 0
@@ -65,7 +65,7 @@ end
6565

6666
# Find index of representative row for each group
6767
function find_index(g::GroupedArray)
68-
groups, ngroups = g.refs, g.ngroups
68+
groups, ngroups = g.groups, g.ngroups
6969
idx = Vector{Int}(undef, ngroups)
7070
filled = fill(false, ngroups)
7171
nfilled = 0
@@ -83,7 +83,7 @@ end
8383

8484

8585
# Data API
86-
DataAPI.refarray(g::GroupedArray) = g.refs
86+
DataAPI.refarray(g::GroupedArray) = g.groups
8787
DataAPI.levels(g::GroupedArray) = 1:g.ngroups
8888
DataAPI.refvalue(g::GroupedArray, ref::Integer) = ref > 0 ? ref : missing
8989

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ g1 = GroupedArray(p1_missing)
2222
@test size(g1) == (10,)
2323
@test length(g1) == 10
2424
@test g1[1] === missing
25-
@test g1.refs[1] === 0
25+
@test g1.groups[1] === 0
2626
@test g1.ngroups == 4
2727

2828

@@ -32,7 +32,7 @@ g1 = GroupedArray(p1_missing)
3232
@test size(g1) == (10,)
3333
@test length(g1) == 10
3434
@test g1[1] === missing
35-
@test g1.refs[1] === 0
35+
@test g1.groups[1] === 0
3636
@test g1[end] === g1[end-1]
3737

3838

@@ -42,7 +42,7 @@ g1 = GroupedArray(p1_missing)
4242
@test size(g1) == (10,)
4343
@test length(g1) == 10
4444
@test g1[1] === missing
45-
@test g1.refs[1] === 0
45+
@test g1.groups[1] === 0
4646

4747
g1 = GroupedArray(p1_missing; coalesce = true)
4848
@test g1[1] === 1

0 commit comments

Comments
 (0)