Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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
@@ -252,11 +252,12 @@ julia> ts[1, "x1"]; # same as above
###

### 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?

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


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.

src/getindex.jl Show resolved Hide resolved
src/getindex.jl Show resolved Hide resolved
@@ -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})

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.

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

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

@@ -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})

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