diff --git a/src/getindex.jl b/src/getindex.jl index e31df21..2b9cdab 100644 --- a/src/getindex.jl +++ b/src/getindex.jl @@ -252,6 +252,7 @@ julia> ts[1, "x1"]; # same as above ### ### Inputs: row scalar, column scalar; Output: scalar + function Base.getindex(ts::TSFrame, i::Int, j::Int) return ts.coredata[i,j+1] end @@ -273,7 +274,7 @@ end ### Inputs: row scalar, column vector; Output: TSFrame function Base.getindex(ts::TSFrame, i::Int, j::AbstractVector{Int}) - TSFrame(ts.coredata[[i], Cols(:Index, j.+1)]) # increment: account for Index + TSFrame(ts.coredata[[i], Cols(:Index, j.+1)]) # increment: account for Index end @@ -285,6 +286,7 @@ function Base.getindex(ts::TSFrame, i::Int, j::AbstractVector{T}) where {T<:Unio end end + function Base.getindex(ts::TSFrame, dt::T, j::AbstractVector{Int}) where {T<:TimeType} idx = findfirst(x -> x == dt, index(ts)) ts[idx, j] @@ -312,6 +314,7 @@ function Base.getindex(ts::TSFrame, i::AbstractVector{Int}, j::Int) ts.coredata[i, j+1] # increment: account for Index end + function Base.getindex(ts::TSFrame, i::AbstractVector{Int}, j::Union{AbstractString, Symbol}) ts.coredata[i, j] end @@ -324,6 +327,7 @@ function Base.getindex(ts::TSFrame, dt::AbstractVector{T}, j::Int) where {T<:Tim ts[idx, j] end + function Base.getindex(ts::TSFrame, dt::AbstractVector{T}, j::Union{AbstractString, Symbol}) where {T<:TimeType} idx = map(d -> findfirst(x -> x == d, index(ts)), dt) if length(idx) == 0 @@ -343,6 +347,7 @@ function Base.getindex(ts::TSFrame, i::AbstractVector{Int}, j::AbstractVector{In TSFrame(ts.coredata[i, Cols(:Index, j.+1)]) # increment: account for Index end + function Base.getindex(ts::TSFrame, i::AbstractVector{Int}, j::AbstractVector{T}) where {T<:Union{AbstractString, Symbol}} if length(unique(map(x -> typeof(x), j))) == 1 TSFrame(ts.coredata[i, Cols(:Index, j)]) @@ -351,6 +356,7 @@ function Base.getindex(ts::TSFrame, i::AbstractVector{Int}, j::AbstractVector{T} end end + function Base.getindex(ts::TSFrame, dt::AbstractVector{T}, j::AbstractVector{Int}) where {T<:TimeType} idx = map(d -> findfirst(x -> x == d, index(ts)), dt) if length(idx) == 0 @@ -359,13 +365,15 @@ function Base.getindex(ts::TSFrame, dt::AbstractVector{T}, j::AbstractVector{Int ts[idx, j] end + function Base.getindex(ts::TSFrame, dt::AbstractVector{D}, j::AbstractVector{T}) where {D<:TimeType, T<:Union{AbstractString, Symbol}} - if length(unique(map(x -> typeof(x), j))) == 1 idx = map(d -> findfirst(x -> x == d, index(ts)), dt) + if length(unique(map(x -> typeof(x), j))) == 1 ts[idx, j] else throw(ArgumentError("The column vector cannot contain both AbstractString and Symbol types.")) - end + end + end ### @@ -385,6 +393,7 @@ function Base.getindex(ts::TSFrame, i::UnitRange, j::Int) ts[collect(i), j] end + function Base.getindex(ts::TSFrame, i::UnitRange, j::Union{AbstractString, Symbol}) ts[collect(i), j] end @@ -395,6 +404,7 @@ function Base.getindex(ts::TSFrame, i::UnitRange, j::AbstractVector{Int}) ts[collect(i), j] end + function Base.getindex(ts::TSFrame, i::UnitRange, j::AbstractVector{T}) where {T<:Union{AbstractString, Symbol}} if length(unique(map(x -> typeof(x), j))) == 1 ts[collect(i), j] @@ -504,6 +514,7 @@ function Base.getindex(ts::TSFrame, ::Colon, j::Int) ts[1:TSFrames.nrow(ts), j] end + function Base.getindex(ts::TSFrame, ::Colon, j::Union{AbstractString, Symbol}) ts[1:TSFrames.nrow(ts), j] end