-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw error in getindex function when string and symbol are passed simultaneously #197
base: main
Are you sure you want to change the base?
Changes from 2 commits
0bc8081
56440c4
449b42c
986af3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,11 +252,12 @@ 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 | ||
|
||
function Base.getindex(ts::TSFrame, i::Int, j::Union{Symbol, String}) | ||
function Base.getindex(ts::TSFrame, i::Int, j::Union{Symbol, AbstractString}) | ||
chiraganand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ts.coredata[i, j] | ||
end | ||
|
||
|
@@ -265,29 +266,40 @@ function Base.getindex(ts::TSFrame, dt::T, j::Int) where {T<:TimeType} | |
ts.coredata[idx, j+1] | ||
end | ||
|
||
function Base.getindex(ts::TSFrame, dt::T, j::Union{String, Symbol}) where {T<:TimeType} | ||
function Base.getindex(ts::TSFrame, dt::T, j::Union{AbstractString, Symbol}) where {T<:TimeType} | ||
chiraganand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
idx = findfirst(x -> x == dt, index(ts)) | ||
ts.coredata[idx, j] | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is only whitespace difference in this line. Can you remove this change too? |
||
end | ||
|
||
function Base.getindex(ts::TSFrame, i::Int, j::AbstractVector{T}) where {T<:Union{String, Symbol}} | ||
TSFrame(ts.coredata[[i], Cols(:Index, j)]) | ||
|
||
function Base.getindex(ts::TSFrame, i::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)]) | ||
else | ||
throw(ArgumentError("The column vector cannot contain both String and Symbol types.")) | ||
end | ||
end | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line. |
||
function Base.getindex(ts::TSFrame, dt::T, j::AbstractVector{Int}) where {T<:TimeType} | ||
idx = findfirst(x -> x == dt, index(ts)) | ||
ts[idx, j] | ||
end | ||
|
||
function Base.getindex(ts::TSFrame, dt::D, j::AbstractVector{T}) where {D<:TimeType, T<:Union{String, Symbol}} | ||
function Base.getindex(ts::TSFrame, dt::D, j::AbstractVector{T}) where {D<:TimeType, T<:Union{AbstractString, Symbol}} | ||
idx = findfirst(x -> x == dt, index(ts)) | ||
ts[idx, j] | ||
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 | ||
### | ||
|
||
|
@@ -302,7 +314,8 @@ 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{String, Symbol}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line. |
||
function Base.getindex(ts::TSFrame, i::AbstractVector{Int}, j::Union{AbstractString, Symbol}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check is needed here. |
||
ts.coredata[i, j] | ||
end | ||
|
||
|
@@ -314,12 +327,18 @@ 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{String, Symbol}) where {T<:TimeType} | ||
|
||
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 | ||
return nothing | ||
else | ||
if length(unique(map(x -> typeof(x), j))) == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check should happen before |
||
ts[idx, j] | ||
else | ||
throw(ArgumentError("The column vector cannot contain both AbstractString and Symbol types.")) | ||
end | ||
end | ||
ts[idx, j] | ||
end | ||
### | ||
|
||
|
@@ -328,10 +347,16 @@ 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{String, Symbol}} | ||
TSFrame(ts.coredata[i, Cols(:Index, j)]) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line. |
||
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)]) | ||
else | ||
throw(ArgumentError("The column vector cannot contain both AbstractString and Symbol types.")) | ||
end | ||
end | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line. |
||
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 | ||
|
@@ -340,9 +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{String, Symbol}} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line. |
||
function Base.getindex(ts::TSFrame, dt::AbstractVector{D}, j::AbstractVector{T}) where {D<:TimeType, T<:Union{AbstractString, Symbol}} | ||
idx = map(d -> findfirst(x -> x == d, index(ts)), dt) | ||
ts[idx, j] | ||
if length(unique(map(x -> typeof(x), j))) == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check should happen before |
||
ts[idx, j] | ||
else | ||
throw(ArgumentError("The column vector cannot contain both AbstractString and Symbol types.")) | ||
end | ||
|
||
end | ||
### | ||
|
||
|
@@ -362,7 +393,8 @@ function Base.getindex(ts::TSFrame, i::UnitRange, j::Int) | |
ts[collect(i), j] | ||
end | ||
|
||
function Base.getindex(ts::TSFrame, i::UnitRange, j::Union{String, Symbol}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line. |
||
function Base.getindex(ts::TSFrame, i::UnitRange, j::Union{AbstractString, Symbol}) | ||
ts[collect(i), j] | ||
end | ||
### | ||
|
@@ -372,8 +404,14 @@ 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{String, Symbol}} | ||
ts[collect(i), j] | ||
|
||
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] | ||
else | ||
throw(ArgumentError("The column vector cannot contain both AbstractString and Symbol types.")) | ||
end | ||
|
||
end | ||
### | ||
|
||
|
@@ -476,7 +514,8 @@ function Base.getindex(ts::TSFrame, ::Colon, j::Int) | |
ts[1:TSFrames.nrow(ts), j] | ||
end | ||
|
||
function Base.getindex(ts::TSFrame, ::Colon, j::Union{String, Symbol}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line. |
||
function Base.getindex(ts::TSFrame, ::Colon, j::Union{AbstractString, Symbol}) | ||
ts[1:TSFrames.nrow(ts), j] | ||
end | ||
### | ||
|
@@ -486,8 +525,13 @@ function Base.getindex(ts::TSFrame, ::Colon, j::AbstractVector{Int}) | |
ts[1:TSFrames.nrow(ts), j] | ||
end | ||
|
||
function Base.getindex(ts::TSFrame, ::Colon, j::AbstractVector{T}) where {T<:Union{String, Symbol}} | ||
ts[1:TSFrames.nrow(ts), j] | ||
function Base.getindex(ts::TSFrame, ::Colon, j::AbstractVector{T}) where {T<:Union{AbstractString, Symbol}} | ||
if length(unique(map(x -> typeof(x), j))) == 1 | ||
ts[1:TSFrames.nrow(ts), j] | ||
else | ||
throw(ArgumentError("The column vector cannot contain both AbstractString and Symbol types.")) | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line. |
||
end | ||
### | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the extra line here?