Skip to content

Commit d492599

Browse files
drizk1rdboyeskdpsingh
authored
fixes count n issue (#145)
* fixes count n issue * gets rid of xs lines in conversion to improve testing * revert type converts, add tests * basic logging for main verbs (#138) * basic logging for select, mutate, and transmute * unit testing for logs * remove deepdiffs dependency * adds tests for logs on the rest of the functions * typo fix * add mutate numbers to log * adds join logging, fix cov x * Fix esedge case for logging with grouped data frames. * :newsize mode logs correct type * add detail for row_change and col_change * add brief docs, bump v, up news * fixes log when grouped mutate, adds fillmissing, dropmissing log support * fixed fxn call * fix join log if stmnt, bump cov attempt w 2tests * add slice log support * change slice_min_max to not use`@filter` bc of logging msg dupes * adds unite, sep, sep_rows * adds logging for nests * minor docs edits for settings * exclude log.jl from code coverage for now --------- Co-authored-by: Daniel Rizk <[email protected]> Co-authored-by: Karandeep Singh <[email protected]> * Updated NEWS.md * Set `fail-on-error` to false for coveralls, removed excluded coverage from log.jl. --------- Co-authored-by: Randall Boyes <[email protected]> Co-authored-by: Karandeep Singh <[email protected]>
1 parent e8df348 commit d492599

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ jobs:
3838
with:
3939
github-token: ${{ github.token }}
4040
path-to-lcov: lcov.info
41+
fail-on-error: false

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# TidierData.jl updates
22

33
## v.0.17.0 - 2025-03-24
4+
- Bugfix: `@count()` can now be called multiple times. If column `n` already exists, then the new column containing the count will be `nn` (and so on).
45
- Adds logging ability to track changes to data frames with `TidierData_set("log", true)`
56
- Adds docs describing logging and code printing
67

src/compound_verbs.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ macro count(df, exprs...)
5555
exprs = parse_blocks(exprs...)
5656
col_names, wt, sort = parse_count_args(exprs...)
5757

58+
local candidate = "n"
59+
while any(x -> (isa(x, Symbol) && x == Symbol(candidate)) ||
60+
(isa(x, Expr) && x == :( $(Symbol(candidate)) )), col_names)
61+
candidate *= "n"
62+
end
63+
local count_name = Symbol(candidate)
64+
5865
col_names_quoted = QuoteNode(col_names)
5966
wt_quoted = QuoteNode(wt)
6067

@@ -69,14 +76,14 @@ macro count(df, exprs...)
6976
end
7077
@chain _ begin
7178
if isnothing($wt_quoted)
72-
@summarize(_, n = n())
79+
@summarize(_, $(count_name) = n())
7380
else
74-
@summarize(_, n = sum(skipmissing($wt)))
81+
@summarize(_, $(count_name) = sum(skipmissing($wt)))
7582
end
7683
end
7784
@chain _ begin
7885
if $sort == true
79-
@arrange(_, desc(n))
86+
@arrange(_, desc($(count_name)))
8087
else
8188
_
8289
end

src/docstrings.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,18 @@ julia> @chain df begin
20372037
1 │ b 15
20382038
2 │ missing 8
20392039
3 │ c 7
2040-
4 │ a 6
2040+
4 │ a 6
2041+
2042+
julia> @chain df begin
2043+
@count(a)
2044+
@count(n)
2045+
end
2046+
2×2 DataFrame
2047+
Row │ n nn
2048+
│ Int64 Int64
2049+
─────┼──────────────
2050+
1 │ 3 2
2051+
2 │ 1 2
20412052
```
20422053
"""
20432054

@@ -2246,6 +2257,9 @@ julia> as_float("1.5")
22462257
22472258
julia> as_float(missing)
22482259
missing
2260+
2261+
julia> as_float("aa")
2262+
missing
22492263
```
22502264
"""
22512265

@@ -2276,6 +2290,9 @@ julia> as_integer("2.5")
22762290
22772291
julia> as_integer(missing)
22782292
missing
2293+
2294+
julia> as_integer("letters")
2295+
missing
22792296
```
22802297
"""
22812298

src/log.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# COV_EXCL_START
2-
31
function generate_log(df_copy, df_output, name, modes)
42
message = ""
53
for mode in modes
@@ -208,6 +206,4 @@ function log_separate_changes(df_before::DataFrame, df_after::DataFrame, into)
208206
end
209207
end
210208
return msg
211-
end
212-
213-
# COV_EXCL_STOP
209+
end

0 commit comments

Comments
 (0)