Skip to content

Commit

Permalink
Clean up isless(::DataFrameRow, ::DataFrameRow)
Browse files Browse the repository at this point in the history
Rewrite the code logic to match that used for Tuple and make it more natural.
Fix tests changed by 6035da8, and which should not use < and ==
(even if the latter falls back to isless).
  • Loading branch information
nalimilan committed Sep 3, 2017
1 parent b293dd7 commit 359763d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/dataframerow/dataframerow.jl
Expand Up @@ -105,8 +105,9 @@ function Base.isless(r1::DataFrameRow, r2::DataFrameRow)
(ncol(r1.df) == ncol(r2.df)) ||
throw(ArgumentError("Rows of the data tables that have different number of columns cannot be compared ($(ncol(df1)) and $(ncol(df2)))"))
@inbounds for i in 1:ncol(r1.df)
isless(r1.df[i][r1.row], r2.df[i][r2.row]) && return true
isequal(r1.df[i][r1.row], r2.df[i][r2.row]) || return false
if !isequal(r1.df[i][r1.row], r2.df[i][r2.row])
return isless(r1.df[i][r1.row], r2.df[i][r2.row])
end
end
return true
return false
end
26 changes: 13 additions & 13 deletions test/dataframerow.jl
Expand Up @@ -21,19 +21,19 @@ module TestDataFrameRow
df4 = DataFrame(a=[1, 1, 2, 2, 2, 2, null, null],
b=Union{Float64, Null}[2.0, 3.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0],
c=[:B, null, :A, :C, :D, :D, :A, :A])
@test DataFrameRow(df4, 1) < DataFrameRow(df4, 2)
@test DataFrameRow(df4, 2) > DataFrameRow(df4, 1)
@test DataFrameRow(df4, 1) == DataFrameRow(df4, 1)
@test DataFrameRow(df4, 1) < DataFrameRow(df4, 3)
@test DataFrameRow(df4, 3) > DataFrameRow(df4, 1)
@test DataFrameRow(df4, 3) < DataFrameRow(df4, 4)
@test DataFrameRow(df4, 4) > DataFrameRow(df4, 3)
@test DataFrameRow(df4, 4) < DataFrameRow(df4, 5)
@test DataFrameRow(df4, 5) > DataFrameRow(df4, 4)
@test DataFrameRow(df4, 6) == DataFrameRow(df4, 5)
@test DataFrameRow(df4, 5) == DataFrameRow(df4, 6)
@test DataFrameRow(df4, 7) < DataFrameRow(df4, 8)
@test DataFrameRow(df4, 8) > DataFrameRow(df4, 7)
@test isless(DataFrameRow(df4, 1), DataFrameRow(df4, 2))
@test !isless(DataFrameRow(df4, 2), DataFrameRow(df4, 1))
@test !isless(DataFrameRow(df4, 1), DataFrameRow(df4, 1))
@test isless(DataFrameRow(df4, 1), DataFrameRow(df4, 3))
@test !isless(DataFrameRow(df4, 3), DataFrameRow(df4, 1))
@test isless(DataFrameRow(df4, 3), DataFrameRow(df4, 4))
@test !isless(DataFrameRow(df4, 4), DataFrameRow(df4, 3))
@test isless(DataFrameRow(df4, 4), DataFrameRow(df4, 5))
@test !isless(DataFrameRow(df4, 5), DataFrameRow(df4, 4))
@test !isless(DataFrameRow(df4, 6), DataFrameRow(df4, 5))
@test !isless(DataFrameRow(df4, 5), DataFrameRow(df4, 6))
@test isless(DataFrameRow(df4, 7), DataFrameRow(df4, 8))
@test !isless(DataFrameRow(df4, 8), DataFrameRow(df4, 7))

# hashing
@test hash(DataFrameRow(df, 1)) != hash(DataFrameRow(df, 2))
Expand Down

0 comments on commit 359763d

Please sign in to comment.