Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes @summary #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# TidierData.jl updates

## v16.3
- Bugfix: `@summary` will only act on numeric/integer columns, instead of throwing an error

## v0.16.2 - 2024-09-03
- Bugfix: `@slice_min` and `@slice_max` respect the `n` argument
- Adds `@head`
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TidierData"
uuid = "fe2206b3-d496-4ee9-a338-6a095c4ece80"
authors = ["Karandeep Singh"]
version = "0.16.2"
version = "0.16.3"

[deps]
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
Expand Down
3 changes: 2 additions & 1 deletion src/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,8 @@ For numerical columns, returns a dataframe with the Q1,Q3, min, max, mean, media
julia> df = DataFrame(a = [1, 2, 3, 4, 5],
b = [missing, 7, 8, 9, 10],
c = [11, missing, 13, 14, missing],
d = [16, 17, 18, 19, 20]);
d = [16.1, 17.2, 18.3, 19.4, 20.5],
e = ["a", "a", "a", "a", "a"]);

julia> @summary(df);

Expand Down
26 changes: 14 additions & 12 deletions src/summary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ function summary_stats(df::DataFrame)
summary_data = []
for column in colnames
col = df[:, column]
col_nonmissing = collect(skipmissing(col))
push!(summary_data, (
Column = column,
Min = minimum(col_nonmissing),
Q1 = quantile(col_nonmissing, 0.25),
Median = median(col_nonmissing),
Mean = mean(col_nonmissing),
Q3 = quantile(col_nonmissing, 0.75),
Max = maximum(col_nonmissing),
Count = length(col_nonmissing),
Missing_Count = count(ismissing, col)
))
if eltype(col) <: Union{Number, Missing}
col_nonmissing = collect(skipmissing(col))
push!(summary_data, (
Column = column,
Min = minimum(col_nonmissing),
Q1 = quantile(col_nonmissing, 0.25),
Median = median(col_nonmissing),
Mean = mean(col_nonmissing),
Q3 = quantile(col_nonmissing, 0.75),
Max = maximum(col_nonmissing),
Count = length(col_nonmissing),
Missing_Count = count(ismissing, col)
))
end
end
return DataFrame(summary_data)
end
Expand Down
Loading