Skip to content

Commit

Permalink
0.7 fixes and test cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Sep 19, 2017
1 parent 5488484 commit e89dddc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 19 deletions.
27 changes: 13 additions & 14 deletions src/subdataframe/subdataframe.jl
Expand Up @@ -5,22 +5,21 @@
##
##############################################################################

include_string("""
immutable SubDataFrame{T <: AbstractVector{Int}} <: AbstractDataFrame
parent::DataFrame
rows::T # maps from subdf row indexes to parent row indexes
function SubDataFrame{T}(parent::DataFrame, rows::T) where {T <: AbstractVector{Int}}
if length(rows) > 0
rmin, rmax = extrema(rows)
if rmin < 1 || rmax > size(parent, 1)
throw(BoundsError())
end
end
new(parent, rows)

struct SubDataFrame{T <: AbstractVector{Int}} <: AbstractDataFrame
parent::DataFrame
rows::T # maps from subdf row indexes to parent row indexes

function SubDataFrame{T}(parent::DataFrame, rows::T) where {T <: AbstractVector{Int}}
if length(rows) > 0
rmin, rmax = extrema(rows)
if rmin < 1 || rmax > size(parent, 1)
throw(BoundsError())
end
end
""")
new(parent, rows)
end
end

"""
A view of row subsets of an AbstractDataFrame
Expand Down
53 changes: 48 additions & 5 deletions test/utils.jl
Expand Up @@ -19,7 +19,7 @@ module TestUtils
if isfile(f)
r1 = r"define initial-reserved-words '\(([^)]+)"
r2 = r"define \(parse-block s(?: \([^)]+\))?\)\s+\(parse-Nary s (?:parse-eq '\([^(]*|down '\([^)]+\) '[^']+ ')\(([^)]+)"
body = readstring(f)
body = read(f, String)
m1, m2 = match(r1, body), match(r2, body)
if m1 == nothing || m2 == nothing
error("Unable to extract keywords from 'julia-parser.scm'.")
Expand Down Expand Up @@ -159,7 +159,8 @@ module TestUtils
CategoricalArray{Union{Int, Null}}(4:7)],
[:arr, :nullarr, :cat, :nullcat])
describe(io, df)
@test String(take!(io)) ==
# Julia 0.7
nullfirst =
"""
arr
Summary Stats:
Expand All @@ -181,7 +182,49 @@ module TestUtils
3rd Quartile: 4.250000
Maximum: 5.000000
Length: 4
Type: Union{$Int, Nulls.Null}
Type: Union{Nulls.Null, $Int}
Number Missing: 0
% Missing: 0.000000
cat
Summary Stats:
Length: 4
Type: CategoricalArrays.CategoricalValue{$Int,$(CategoricalArrays.DefaultRefType)}
Number Unique: 4
nullcat
Summary Stats:
Length: 4
Type: Union{Nulls.Null, CategoricalArrays.CategoricalValue{$Int,$(CategoricalArrays.DefaultRefType)}}
Number Unique: 4
Number Missing: 0
% Missing: 0.000000
"""
# Julia 0.6
nullsecond =
"""
arr
Summary Stats:
Mean: 2.500000
Minimum: 1.000000
1st Quartile: 1.750000
Median: 2.500000
3rd Quartile: 3.250000
Maximum: 4.000000
Length: 4
Type: $Int
nullarr
Summary Stats:
Mean: 3.500000
Minimum: 2.000000
1st Quartile: 2.750000
Median: 3.500000
3rd Quartile: 4.250000
Maximum: 5.000000
Length: 4
Type: Union{Nulls.Null, $Int}
Number Missing: 0
% Missing: 0.000000
Expand All @@ -194,11 +237,11 @@ module TestUtils
nullcat
Summary Stats:
Length: 4
Type: Union{CategoricalArrays.CategoricalValue{$Int,$(CategoricalArrays.DefaultRefType)}, Nulls.Null}
Type: Union{Nulls.Null, CategoricalArrays.CategoricalValue{$Int,$(CategoricalArrays.DefaultRefType)}}
Number Unique: 4
Number Missing: 0
% Missing: 0.000000
"""
end
end
end

0 comments on commit e89dddc

Please sign in to comment.