@@ -27,7 +27,9 @@ function fill_refs!(refs::AbstractArray, X::AbstractArray,
2727 end
2828end
2929
30- const CUT_FMT = Printf. Format (" %.*g" )
30+ if VERSION >= v " 1.10"
31+ const CUT_FMT = Printf. Format (" %.*g" )
32+ end
3133
3234"""
3335 CategoricalArrays.default_formatter(from, to, i::Integer;
@@ -44,12 +46,21 @@ If they are floating points values, breaks are turned into to strings using
4446function default_formatter (from, to, i:: Integer ;
4547 leftclosed:: Bool , rightclosed:: Bool ,
4648 sigdigits:: Integer )
47- from_str = from isa AbstractFloat ?
48- Printf. format (CUT_FMT, sigdigits, from) :
49- string (from)
50- to_str = to isa AbstractFloat ?
51- Printf. format (CUT_FMT, sigdigits, to) :
52- string (to)
49+ @static if VERSION >= v " 1.10"
50+ from_str = from isa AbstractFloat ?
51+ Printf. format (CUT_FMT, sigdigits, from) :
52+ string (from)
53+ to_str = to isa AbstractFloat ?
54+ Printf. format (CUT_FMT, sigdigits, to) :
55+ string (to)
56+ else
57+ from_str = from isa AbstractFloat ?
58+ Printf. format (Printf. Format (" %.$(sigdigits) g" ), from) :
59+ string (from)
60+ to_str = to isa AbstractFloat ?
61+ Printf. format (Printf. Format (" %.$(sigdigits) g" ), to) :
62+ string (to)
63+ end
5364 string (leftclosed ? " [" : " (" , from_str, " , " , to_str, rightclosed ? " ]" : " )" )
5465end
5566
@@ -164,19 +175,7 @@ julia> cut(-1:0.5:1, 3, labels=fmt)
164175 extend:: Union{Bool, Missing} = false ,
165176 labels:: Union{AbstractVector{<:SupportedTypes},Function} = default_formatter,
166177 sigdigits:: Integer = 3 ,
167- allowmissing:: Union{Bool, Nothing} = nothing ,
168- allow_missing:: Union{Bool, Nothing} = nothing ,
169178 allowempty:: Bool = false )
170- if allow_missing != = nothing
171- Base. depwarn (" allow_missing argument is deprecated, use extend=missing instead" ,
172- :cut )
173- extend = missing
174- end
175- if allowmissing != = nothing
176- Base. depwarn (" allowmissing argument is deprecated, use extend=missing instead" ,
177- :cut )
178- extend = missing
179- end
180179 return _cut (x, breaks, extend, labels, sigdigits, allowempty)
181180end
182181
@@ -251,8 +250,13 @@ function _cut(x::AbstractArray{T, N}, breaks::AbstractVector,
251250 b2 = breaks[i]
252251 isequal (b1, b2) && continue
253252
254- b1_str = Printf. format (CUT_FMT, sigdigits, b1)
255- b2_str = Printf. format (CUT_FMT, sigdigits, b2)
253+ @static if VERSION >= v " 1.9"
254+ b1_str = Printf. format (CUT_FMT, sigdigits, b1)
255+ b2_str = Printf. format (CUT_FMT, sigdigits, b2)
256+ else
257+ b1_str = Printf. format (Printf. Format (" %.$(sigdigits) g" ), b1)
258+ b2_str = Printf. format (Printf. Format (" %.$(sigdigits) g" ), b2)
259+ end
256260 if b1_str == b2_str
257261 sigdigits += 1
258262 break
0 commit comments