Skip to content

Throw error in getindex function when string and symbol are passed simultaneously#197

Open
siddjain444 wants to merge 4 commits intoxKDR:mainfrom
siddjain444:t175_julia_version
Open

Throw error in getindex function when string and symbol are passed simultaneously#197
siddjain444 wants to merge 4 commits intoxKDR:mainfrom
siddjain444:t175_julia_version

Conversation

@siddjain444
Copy link
Contributor

@siddjain444 siddjain444 commented Apr 25, 2024

Updating the getindex function to throw argument error when string and symbol are passed simultaneously as input to the function.
Closes #194, #190

…d symbol are passed simultaneously as input to the function
@siddjain444 siddjain444 requested a review from chiraganand April 25, 2024 09:14
###

### Inputs: row scalar, column scalar; Output: scalar

Copy link
Member

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?

### 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
Copy link
Member

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
end


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line.

end

function Base.getindex(ts::TSFrame, i::UnitRange, j::Union{String, Symbol})

Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

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 -> ....

if length(idx) == 0
return nothing
else
if length(unique(map(x -> typeof(x), j))) == 1
Copy link
Member

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 -> ...).

end

function Base.getindex(ts::TSFrame, ::Colon, j::Union{String, Symbol})

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disallow Vector{Union{String, Symbol}} to have both types in a single vector

2 participants