Skip to content

Commit f6b3c0e

Browse files
authored
Merge pull request #247 from cjprybol/cjp/describe
Move some `describe` code from DataFrames/Tables -> StatsBase
2 parents 1b815de + e49e82f commit f6b3c0e

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

src/scalarstats.jl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,12 @@ end
554554

555555
function Base.show(io::IO, ss::SummaryStats)
556556
println(io, "Summary Stats:")
557-
@printf(io, "Mean: %.6f\n", ss.mean)
558-
@printf(io, "Minimum: %.6f\n", ss.min)
559-
@printf(io, "1st Quartile: %.6f\n", ss.q25)
560-
@printf(io, "Median: %.6f\n", ss.median)
561-
@printf(io, "3rd Quartile: %.6f\n", ss.q75)
562-
@printf(io, "Maximum: %.6f\n", ss.max)
557+
@printf(io, "Mean: %.6f\n", ss.mean)
558+
@printf(io, "Minimum: %.6f\n", ss.min)
559+
@printf(io, "1st Quartile: %.6f\n", ss.q25)
560+
@printf(io, "Median: %.6f\n", ss.median)
561+
@printf(io, "3rd Quartile: %.6f\n", ss.q75)
562+
@printf(io, "Maximum: %.6f\n", ss.max)
563563
end
564564

565565

@@ -570,4 +570,16 @@ Pretty-print the summary statistics provided by `summarystats`:
570570
the mean, minimum, 25th percentile, median, 75th percentile, and
571571
maximum.
572572
"""
573-
describe{T<:Real}(a::AbstractArray{T}) = show(summarystats(a))
573+
describe(a::AbstractArray) = describe(STDOUT, a)
574+
function describe{T<:Real}(io::IO, a::AbstractArray{T})
575+
show(io, summarystats(a))
576+
println(io, "Length: $(length(a))")
577+
println(io, "Type: $(string(eltype(a)))")
578+
end
579+
function describe(io::IO, a::AbstractArray)
580+
println(io, "Summary Stats:")
581+
println(io, "Length: $(length(a))")
582+
println(io, "Type: $(string(eltype(a)))")
583+
println(io, "Number Unique: $(length(unique(a)))")
584+
return
585+
end

test/misc.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,25 @@ x = [2, 1, 3, 3, 2]
3535
x = ["b", "a", "c", "c", "b"]
3636
@test indicatormat(x) == I
3737
@test full(indicatormat(x; sparse=true)) == I
38+
39+
io = IOBuffer()
40+
describe(io, collect(1:10))
41+
@test String(take!(io)) == """
42+
Summary Stats:
43+
Mean: 5.500000
44+
Minimum: 1.000000
45+
1st Quartile: 3.250000
46+
Median: 5.500000
47+
3rd Quartile: 7.750000
48+
Maximum: 10.000000
49+
Length: 10
50+
Type: $Int
51+
"""
52+
53+
describe(io, fill("s", 3))
54+
@test String(take!(io)) == """
55+
Summary Stats:
56+
Length: 3
57+
Type: String
58+
Number Unique: 1
59+
"""

0 commit comments

Comments
 (0)