From b97ec42dda7a8088a48d7c367d1e0224b5edf899 Mon Sep 17 00:00:00 2001 From: Jared Lumpe Date: Mon, 9 Dec 2019 13:29:03 -0800 Subject: [PATCH] Restrict getindex(::GroupedDataFrame, ::AbstractArray) to 1D arrays only --- docs/src/lib/indexing.md | 2 +- src/groupeddataframe/grouping.jl | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/src/lib/indexing.md b/docs/src/lib/indexing.md index c3666c9a38..73d1f828fd 100644 --- a/docs/src/lib/indexing.md +++ b/docs/src/lib/indexing.md @@ -221,7 +221,7 @@ The elements of a `GroupedDataFrame` are [`SubDataFrame`](@ref)s of its parent. * `gd[key::GroupKey]` -> Get the group corresponding to the [`GroupKey`](@ref) `key` (one of the elements of the vector returned by [`keys(::GroupedDataFrame)`](@ref)). This should be nearly as fast as integer indexing. -* `gd[a::AbstractArray]` -> Select multiple groups and return them in a new +* `gd[a::AbstractVector]` -> Select multiple groups and return them in a new `GroupedDataFrame` object. Groups may be selected by integer position using an array of `Integer`s or `Bool`s, similar to a standard array. Alternatively the array may contain keys of any of the types supported for dictionary-like diff --git a/src/groupeddataframe/grouping.jl b/src/groupeddataframe/grouping.jl index cc55139ac7..214f50d38f 100644 --- a/src/groupeddataframe/grouping.jl +++ b/src/groupeddataframe/grouping.jl @@ -195,7 +195,7 @@ Base.getindex(gd::GroupedDataFrame, idx::Integer) = view(gd.parent, gd.idx[gd.starts[idx]:gd.ends[idx]], :) # Array of integers -function Base.getindex(gd::GroupedDataFrame, idxs::AbstractArray{T}) where {T<:Integer} +function Base.getindex(gd::GroupedDataFrame, idxs::AbstractVector{T}) where {T<:Integer} new_starts = gd.starts[idxs] new_ends = gd.ends[idxs] if !allunique(new_starts) @@ -443,12 +443,12 @@ end Base.getindex(gd::GroupedDataFrame, key::GroupKeyTypes) = gd[_findgroup(gd, key)] # Array indexing with dictionary-like keys -Base.getindex(gd::GroupedDataFrame, idxs::AbstractArray{T}) where {T<:GroupKeyTypes} = gd[[_findgroup(gd, k) for k in idxs]] +Base.getindex(gd::GroupedDataFrame, idxs::AbstractVector{T}) where {T<:GroupKeyTypes} = gd[[_findgroup(gd, k) for k in idxs]] # InvertedIndex function Base.getindex(gd::GroupedDataFrame, idx::InvertedIndex{T}) where T selected = trues(length(gd)) - if T <: AbstractArray + if T <: AbstractVector selected[[_findgroup(gd, k) for k in idx.skip]] .= false else selected[_findgroup(gd, idx.skip)] = false @@ -457,7 +457,7 @@ function Base.getindex(gd::GroupedDataFrame, idx::InvertedIndex{T}) where T end # InvertedIndex wrapping a boolean array -Base.getindex(gd::GroupedDataFrame, idx::InvertedIndex{T}) where {T<:AbstractArray{Bool}} = gd[.!idx.skip] +Base.getindex(gd::GroupedDataFrame, idx::InvertedIndex{T}) where {T<:AbstractVector{Bool}} = gd[.!idx.skip] """ get(gd::GroupedDataFrame, key, default)