Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-Authored-By: Milan Bouchet-Valat <nalimilan@club.fr>
  • Loading branch information
greimel and nalimilan committed Sep 20, 2019
1 parent 624b724 commit 8a0e2e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
17 changes: 4 additions & 13 deletions src/extras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,23 @@ also accept them.
# Examples
```jldoctest
julia> using CategoricalArrays
julia> x = -1:0.5:1;
julia> cut(x, [0, 1], extend=true)
julia> cut(-1:0.5:1, [0, 1], extend=true)
5-element CategoricalArray{String,1,UInt32}:
"[-1.0, 0.0)"
"[-1.0, 0.0)"
"[0.0, 1.0]"
"[0.0, 1.0]"
"[0.0, 1.0]"
julia> x = -1:0.5:1;
julia> cut(x, 2)
julia> cut(-1:0.5:1, 2)
5-element CategoricalArray{String,1,UInt32}:
"[-1.0, 0.0)"
"[-1.0, 0.0)"
"[0.0, 1.0]"
"[0.0, 1.0]"
"[0.0, 1.0]"
julia> x = -1:0.5:1;
julia> cut(x, 2, labels=["A", "B"])
julia> cut(-1:0.5:1, 2, labels=["A", "B"])
5-element CategoricalArray{String,1,UInt32}:
"A"
"A"
Expand All @@ -108,7 +100,7 @@ julia> cut(x, 2, labels=["A", "B"])
julia> fmt(from, to, i; closed) = "grp $i ($from//$to)"
fmt (generic function with 1 method)
julia> cut(x, 3, labels=fmt)
julia> cut(-1:0.5:1, 3, labels=fmt)
5-element CategoricalArray{String,1,UInt32}:
"grp 1 (-1.0//-0.333333)"
"grp 1 (-1.0//-0.333333)"
Expand All @@ -121,7 +113,6 @@ function cut(x::AbstractArray{T, N}, breaks::AbstractVector;
extend::Bool=false,
labels::Union{AbstractVector{<:AbstractString},Function}=default_formatter,
allow_missing::Bool=false) where {T, N}

if !issorted(breaks)
breaks = sort(breaks)
end
Expand Down
2 changes: 1 addition & 1 deletion test/15_extras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ end
@test levels(x) == ["[2.0, 3.5)", "[3.5, 5.0]"]
end

@testset "formatter function" begin
@testset "cut with formatter function" begin
my_formatter(from, to, i; closed) = "$i: $from -- $to"

x = 0.15:0.20:0.95
Expand Down

0 comments on commit 8a0e2e5

Please sign in to comment.