Skip to content

Commit

Permalink
Fix handling of non-Int row indices (#1177)
Browse files Browse the repository at this point in the history
Non-Int row-indices were not being correctly converted to Int.

- explicit conversion to Vector{Int}
- test-cases added
  • Loading branch information
joshbode authored and ararslan committed Apr 12, 2017
1 parent ef8b8f3 commit 4652000
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/subdataframe/subdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,15 @@ immutable SubDataFrame{T <: AbstractVector{Int}} <: AbstractDataFrame
end
end

function SubDataFrame{T <: AbstractVector{Int}}(parent::DataFrame, rows::T)
return SubDataFrame{T}(parent, rows)
function SubDataFrame{T <: Integer}(parent::DataFrame, rows::AbstractVector{T})
rows = convert(Vector{Int}, rows)
return SubDataFrame{typeof(rows)}(parent, rows)
end

function SubDataFrame(parent::DataFrame, row::Integer)
return SubDataFrame(parent, [row])
end

function SubDataFrame{S <: Integer}(parent::DataFrame, rows::AbstractVector{S})
return view(parent, Int(rows))
end


function Base.view{S <: Real}(df::DataFrame, rowinds::AbstractVector{S})
return SubDataFrame(df, rowinds)
Expand Down
4 changes: 4 additions & 0 deletions test/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ module TestData
@test size(sdf6a) == (1,3)
sdf6d = view(df6, [1,3], :B)
@test size(sdf6d) == (2,1)
sdf6e = view(df6, 0x01)
@test size(sdf6e) == (1,3)
sdf6f = view(df6, UInt64[1, 2])
@test size(sdf6f) == (2,3)

#test_group("ref")
@test sdf6a[1,2] == 4
Expand Down

0 comments on commit 4652000

Please sign in to comment.