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

Fix handling of non-Int row indices #1177

Merged
merged 1 commit into from
Apr 12, 2017
Merged

Conversation

joshbode
Copy link
Contributor

@joshbode joshbode commented Mar 26, 2017

Non-Int64 row-indices were not being correctly converted to Int64.

  • explicit conversion to Vector{Int64}
  • test-cases added

Interestingly, this came up only when DataFrames was precompiled into a userimg (see JuliaLang/julia#21164) and only after the rename of sub() to view()

@@ -71,7 +71,7 @@ function SubDataFrame(parent::DataFrame, row::Integer)
end

function SubDataFrame{S <: Integer}(parent::DataFrame, rows::AbstractVector{S})
return view(parent, Int(rows))
return SubDataFrame{Vector{Int}}(parent, convert(Vector{Int}, rows))
Copy link
Member

Choose a reason for hiding this comment

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

We should only convert to AbstractVector{Int} since that's what the type accepts. I suspect the Int(rows) expression comes from an automated replacement which was done after int(x) was deprecated. This was effectively equivalent to convert(AbstractVector{Int}, rows).

Also it seems it would more sense to remove this method and put this line into the generic constructor with rows::T above.

@nalimilan nalimilan changed the title Fix handling of non-Int64 row indices Fix handling of non-Int row indices Mar 26, 2017
@nalimilan
Copy link
Member

Thanks. Note that Int is not necessarily Int64, it's Int32 on 32-bit.

@joshbode
Copy link
Contributor Author

Good points - I'll try to merge this into the earlier constructor and come back

@@ -62,18 +62,14 @@ immutable SubDataFrame{T <: AbstractVector{Int}} <: AbstractDataFrame
end
end

function SubDataFrame{T <: AbstractVector{Int}}(parent::DataFrame, rows::T)
return SubDataFrame{T}(parent, rows)
function SubDataFrame{S <: Integer}(parent::DataFrame, rows::AbstractVector{S})
Copy link
Member

Choose a reason for hiding this comment

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

Minor point, but using T is more common.

function SubDataFrame{T <: AbstractVector{Int}}(parent::DataFrame, rows::T)
return SubDataFrame{T}(parent, rows)
function SubDataFrame{S <: Integer}(parent::DataFrame, rows::AbstractVector{S})
return SubDataFrame{AbstractVector{Int}}(parent, convert(AbstractVector{Int}, rows))
Copy link
Member

Choose a reason for hiding this comment

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

{AbstractVector{Int}} isn't correct here: it should be the actual concrete type to which rows was converted. So you need to store the result of the conversion in an object first, and call typeof on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK - thanks, that makes sense

Non-Int row-indices were not being correctly converted to Int.

- explicit conversion to Vector{Int}
- test-cases added
@ararslan ararslan merged commit 4652000 into JuliaData:master Apr 12, 2017
@ararslan
Copy link
Member

Thanks!

@iamed2
Copy link

iamed2 commented Apr 19, 2017

This also happened with --compilecache=no (see #1182)

@joshbode
Copy link
Contributor Author

All my favourite Julia bugs seem to tie back to precompilation :)

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.

4 participants