-
Notifications
You must be signed in to change notification settings - Fork 22
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?
Conversation
…d symbol are passed simultaneously as input to the function
@@ -252,11 +252,12 @@ julia> ts[1, "x1"]; # same as above | |||
### | |||
|
|||
### Inputs: row scalar, column scalar; Output: scalar | |||
|
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?
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 comment
The 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 | ||
|
||
|
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.
Empty line.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The check should happen before idx = map(d -> ...
.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This check should happen before idx = map(d -> ...)
.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line.
Updating the getindex function to throw argument error when string and symbol are passed simultaneously as input to the function.
Closes #194, #190