From 4652000f0984157702b4c8e7a2bc054b90a4e7d3 Mon Sep 17 00:00:00 2001 From: Josh Bode Date: Thu, 13 Apr 2017 04:11:58 +1000 Subject: [PATCH] Fix handling of non-Int row indices (#1177) Non-Int row-indices were not being correctly converted to Int. - explicit conversion to Vector{Int} - test-cases added --- src/subdataframe/subdataframe.jl | 9 +++------ test/data.jl | 4 ++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/subdataframe/subdataframe.jl b/src/subdataframe/subdataframe.jl index 23cacdfe9f..98a7e3b9e9 100644 --- a/src/subdataframe/subdataframe.jl +++ b/src/subdataframe/subdataframe.jl @@ -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) diff --git a/test/data.jl b/test/data.jl index 1076042afe..8f3c086458 100644 --- a/test/data.jl +++ b/test/data.jl @@ -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