Skip to content

Commit

Permalink
Merge pull request #137 from codedthinking/0.4-bugfixes
Browse files Browse the repository at this point in the history
0.4 bugfixes
  • Loading branch information
gergelyattilakiss authored Jul 5, 2024
2 parents 3305cff + d2f14fc commit 912c35a
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Kezdi"
uuid = "48308a23-c29e-446c-b4c0-d9446a767439"
authors = ["Miklos Koren <[email protected]>", "Gergely Attila Kiss <[email protected]>"]
version = "0.4.3"
version = "0.4.4"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
14 changes: 9 additions & 5 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ end

| Command | Stata | Julia 1st run | Julia 2nd run | Speedup |
| ------------ | ----- | ------------- | ------------- | ------- |
| `@egen` | 4.90s | 1.60s | 0.41s | 10x |
| `@collapse` | 0.92s | 0.18s | 0.13s | 8x |
| `@tabulate` | 2.14s | 0.46s | 0.10s | 20x |
| `@summarize` | 10.40s | 0.58s | 0.37s | 28x |
| `@regress` | 0.89s | 1.93s | 0.16s | 6x |
| `@egen` | 4.90s | 1.36s | 0.59s | 8x |
| `@collapse` | 0.92s | 0.39s | 0.39s | 2x |
| `@tabulate` | 2.14s | 0.68s | 0.10s | 21x |
| `@summarize` | 10.40s | 0.58s | 0.46s | 22x |
| `@regress` | 0.89s | 1.95s | 0.14s | 6x |

See the benchmarking code for [Stata](https://github.com/codedthinking/Kezdi.jl/blob/main/examples/benchmark.do) and [Kezdi.jl](https://github.com/codedthinking/Kezdi.jl/blob/main/examples/benchmark.jl).

Expand Down Expand Up @@ -331,6 +331,10 @@ rowcount
DNV
```

```@docs
keep_only_values
```


## Acknowledgements
[^stata]: Stata is a registered trademark of StataCorp LLC. Kezdi.jl is not affiliated with StataCorp LLC.
Expand Down
4 changes: 3 additions & 1 deletion src/Kezdi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
Kezdi.jl is a Julia package for data manipulation and analysis. It is inspired by Stata, but it is written in Julia, which makes it faster and more flexible. It is designed to be used in the Julia REPL, but it can also be used in Jupyter notebooks or in scripts.
"""
module Kezdi
export @generate, @replace, @egen, @collapse, @keep, @drop, @summarize, @regress, use, @use, @tabulate, rowcount, distinct, @count, @sort, @order, getdf, setdf, @list, @head, @tail, @names, display_and_return, @rename
export @generate, @replace, @egen, @collapse, @keep, @drop, @summarize, @regress, use, @use, @tabulate, @count, @sort, @order, getdf, setdf, @list, @head, @tail, @names, @rename

export display_and_return, keep_only_values, rowcount, distinct

using Reexport
using Logging
Expand Down
14 changes: 9 additions & 5 deletions src/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,21 @@ function vectorize_function_calls(expr::Any)
elseif fname == :DNV
return expr.args[2]
elseif fname in DO_NOT_VECTORIZE || (!(fname in ALWAYS_VECTORIZE) && (length(methodswith(Vector, eval(fname); supertypes=true)) > 0))
return Expr(expr.head, fname,
Expr(:call, :collect,
Expr(:call, :skipmissing,
vectorize_function_calls.(expr.args[2:end])...)
))
skipmissing_each_arg = [Expr(:call, :keep_only_values, vectorize_function_calls(arg)) for arg in expr.args[2:end]]
return Expr(expr.head, fname, skipmissing_each_arg...)
else
return Expr(Symbol("."), fname,
Expr(:tuple,
vectorize_function_calls.(expr.args[2:end])...)
)
end
elseif is_operator(expr.head) && !is_dotted_operator(expr.head) && expr.head in SYNTACTIC_OPERATORS
# special handling of syntactic operators like &&, ||, etc.
# these are not called as a function
op = expr.head
dot_op = Symbol("." * String(op))
return Expr(dot_op,
vectorize_function_calls.(expr.args)...)
elseif is_operator(expr.args[1]) && !is_dotted_operator(expr.args[1])
op = expr.args[1]
dot_op = Symbol("." * String(op))
Expand Down
6 changes: 5 additions & 1 deletion src/consts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ const OPTIONS = (
:variables
)

const OPERATORS = tuple([Symbol(x) for x in split(raw"= += -= −= *= /= //= |\\=| ^= ÷= %= <<= >>= >>>= |\|=| &= ⊻= ≔ ⩴ ≕ ← → ↔ ↚ ↛ ↞ ↠ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔ ⇴ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿ ⟵ ⟶ ⟷ ⟹ ⟺ ⟻ ⟼ ⟽ ⟾ ⟿ ⤀ ⤁ ⤂ ⤃ ⤄ ⤅ ⤆ ⤇ ⤌ ⤍ ⤎ ⤏ ⤐ ⤑ ⤔ ⤕ ⤖ ⤗ ⤘ ⤝ ⤞ ⤟ ⤠ ⥄ ⥅ ⥆ ⥇ ⥈ ⥊ ⥋ ⥎ ⥐ ⥒ ⥓ ⥖ ⥗ ⥚ ⥛ ⥞ ⥟ ⥢ ⥤ ⥦ ⥧ ⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥰ ⧴ ⬱ ⬰ ⬲ ⬳ ⬴ ⬵ ⬶ ⬷ ⬸ ⬹ ⬺ ⬻ ⬼ ⬽ ⬾ ⬿ ⭀ ⭁ ⭂ ⭃ ⥷ ⭄ ⥺ ⭇ ⭈ ⭉ ⭊ ⭋ ⭌ ← → ⇜ ⇝ ↜ ↝ ↩ ↪ ↫ ↬ ↼ ↽ ⇀ ⇁ ⇄ ⇆ ⇇ ⇉ ⇋ ⇌ ⇚ ⇛ ⇠ ⇢ ↷ ↶ ↺ ↻ ~ --> <-- <--> > < >= ≥ <= ≤ == === ≡ != ≠ !== ≢ ∈ ∉ ∋ ∌ ⊆ ⊈ ⊂ ⊄ ⊊ ∝ ∊ ∍ ∥ ∦ ∷ ∺ ∻ ∽ ∾ ≁ ≃ ≂ ≄ ≅ ≆ ≇ ≈ ≉ ≊ ≋ ≌ ≍ ≎ ≐ ≑ ≒ ≓ ≖ ≗ ≘ ≙ ≚ ≛ ≜ ≝ ≞ ≟ ≣ ≦ ≧ ≨ ≩ ≪ ≫ ≬ ≭ ≮ ≯ ≰ ≱ ≲ ≳ ≴ ≵ ≶ ≷ ≸ ≹ ≺ ≻ ≼ ≽ ≾ ≿ ⊀ ⊁ ⊃ ⊅ ⊇ ⊉ ⊋ ⊏ ⊐ ⊑ ⊒ ⊜ ⊩ ⊬ ⊮ ⊰ ⊱ ⊲ ⊳ ⊴ ⊵ ⊶ ⊷ ⋍ ⋐ ⋑ ⋕ ⋖ ⋗ ⋘ ⋙ ⋚ ⋛ ⋜ ⋝ ⋞ ⋟ ⋠ ⋡ ⋢ ⋣ ⋤ ⋥ ⋦ ⋧ ⋨ ⋩ ⋪ ⋫ ⋬ ⋭ ⋲ ⋳ ⋴ ⋵ ⋶ ⋷ ⋸ ⋹ ⋺ ⋻ ⋼ ⋽ ⋾ ⋿ ⟈ ⟉ ⟒ ⦷ ⧀ ⧁ ⧡ ⧣ ⧤ ⧥ ⩦ ⩧ ⩪ ⩫ ⩬ ⩭ ⩮ ⩯ ⩰ ⩱ ⩲ ⩳ ⩵ ⩶ ⩷ ⩸ ⩹ ⩺ ⩻ ⩼ ⩽ ⩾ ⩿ ⪀ ⪁ ⪂ ⪃ ⪄ ⪅ ⪆ ⪇ ⪈ ⪉ ⪊ ⪋ ⪌ ⪍ ⪎ ⪏ ⪐ ⪑ ⪒ ⪓ ⪔ ⪕ ⪖ ⪗ ⪘ ⪙ ⪚ ⪛ ⪜ ⪝ ⪞ ⪟ ⪠ ⪡ ⪢ ⪣ ⪤ ⪥ ⪦ ⪧ ⪨ ⪩ ⪪ ⪫ ⪬ ⪭ ⪮ ⪯ ⪰ ⪱ ⪲ ⪳ ⪴ ⪵ ⪶ ⪷ ⪸ ⪹ ⪺ ⪻ ⪼ ⪽ ⪾ ⪿ ⫀ ⫁ ⫂ ⫃ ⫄ ⫅ ⫆ ⫇ ⫈ ⫉ ⫊ ⫋ ⫌ ⫍ ⫎ ⫏ ⫐ ⫑ ⫒ ⫓ ⫔ ⫕ ⫖ ⫗ ⫘ ⫙ ⫷ ⫸ ⫹ ⫺ ⊢ ⊣ ⟂ ⫪ ⫫ <: >: + - − ¦ |\|| ⊕ ⊖ ⊞ ⊟ |++| ∪ ∨ ⊔ ± ∓ ∔ ∸ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⟇ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣ * / ⌿ ÷ % & · · ⋅ ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗ ⨟ // ^ ↑ ↓ ⇵ ⟰ ⟱ ⤈ ⤉ ⤊ ⤋ ⤒ ⤓ ⥉ ⥌ ⥍ ⥏ ⥑ ⥔ ⥕ ⥘ ⥙ ⥜ ⥝ ⥠ ⥡ ⥣ ⥥ ⥮ ⥯ ↑ ↓ << >> >>>")]...)
const SYNTACTIC_OPERATORS = tuple([Symbol(x) for x in split(raw"&& || += -= *= /= //= \= ^= ÷= %= <<= >>= >>>= |= &= ⊻=")]...)
const OPERATORS = tuple(
vcat(
[Symbol(x) for x in split(raw"= += -= −= *= /= //= \= ^= ÷= %= <<= >>= >>>= |= &= ⊻= ≔ ⩴ ≕ ← → ↔ ↚ ↛ ↞ ↠ ↢ ↣ ↦ ↤ ↮ ⇎ ⇍ ⇏ ⇐ ⇒ ⇔ ⇴ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿ ⟵ ⟶ ⟷ ⟹ ⟺ ⟻ ⟼ ⟽ ⟾ ⟿ ⤀ ⤁ ⤂ ⤃ ⤄ ⤅ ⤆ ⤇ ⤌ ⤍ ⤎ ⤏ ⤐ ⤑ ⤔ ⤕ ⤖ ⤗ ⤘ ⤝ ⤞ ⤟ ⤠ ⥄ ⥅ ⥆ ⥇ ⥈ ⥊ ⥋ ⥎ ⥐ ⥒ ⥓ ⥖ ⥗ ⥚ ⥛ ⥞ ⥟ ⥢ ⥤ ⥦ ⥧ ⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥰ ⧴ ⬱ ⬰ ⬲ ⬳ ⬴ ⬵ ⬶ ⬷ ⬸ ⬹ ⬺ ⬻ ⬼ ⬽ ⬾ ⬿ ⭀ ⭁ ⭂ ⭃ ⥷ ⭄ ⥺ ⭇ ⭈ ⭉ ⭊ ⭋ ⭌ ← → ⇜ ⇝ ↜ ↝ ↩ ↪ ↫ ↬ ↼ ↽ ⇀ ⇁ ⇄ ⇆ ⇇ ⇉ ⇋ ⇌ ⇚ ⇛ ⇠ ⇢ ↷ ↶ ↺ ↻ ~ --> <-- <--> > < >= ≥ <= ≤ == === ≡ != ≠ !== ≢ ∈ ∉ ∋ ∌ ⊆ ⊈ ⊂ ⊄ ⊊ ∝ ∊ ∍ ∥ ∦ ∷ ∺ ∻ ∽ ∾ ≁ ≃ ≂ ≄ ≅ ≆ ≇ ≈ ≉ ≊ ≋ ≌ ≍ ≎ ≐ ≑ ≒ ≓ ≖ ≗ ≘ ≙ ≚ ≛ ≜ ≝ ≞ ≟ ≣ ≦ ≧ ≨ ≩ ≪ ≫ ≬ ≭ ≮ ≯ ≰ ≱ ≲ ≳ ≴ ≵ ≶ ≷ ≸ ≹ ≺ ≻ ≼ ≽ ≾ ≿ ⊀ ⊁ ⊃ ⊅ ⊇ ⊉ ⊋ ⊏ ⊐ ⊑ ⊒ ⊜ ⊩ ⊬ ⊮ ⊰ ⊱ ⊲ ⊳ ⊴ ⊵ ⊶ ⊷ ⋍ ⋐ ⋑ ⋕ ⋖ ⋗ ⋘ ⋙ ⋚ ⋛ ⋜ ⋝ ⋞ ⋟ ⋠ ⋡ ⋢ ⋣ ⋤ ⋥ ⋦ ⋧ ⋨ ⋩ ⋪ ⋫ ⋬ ⋭ ⋲ ⋳ ⋴ ⋵ ⋶ ⋷ ⋸ ⋹ ⋺ ⋻ ⋼ ⋽ ⋾ ⋿ ⟈ ⟉ ⟒ ⦷ ⧀ ⧁ ⧡ ⧣ ⧤ ⧥ ⩦ ⩧ ⩪ ⩫ ⩬ ⩭ ⩮ ⩯ ⩰ ⩱ ⩲ ⩳ ⩵ ⩶ ⩷ ⩸ ⩹ ⩺ ⩻ ⩼ ⩽ ⩾ ⩿ ⪀ ⪁ ⪂ ⪃ ⪄ ⪅ ⪆ ⪇ ⪈ ⪉ ⪊ ⪋ ⪌ ⪍ ⪎ ⪏ ⪐ ⪑ ⪒ ⪓ ⪔ ⪕ ⪖ ⪗ ⪘ ⪙ ⪚ ⪛ ⪜ ⪝ ⪞ ⪟ ⪠ ⪡ ⪢ ⪣ ⪤ ⪥ ⪦ ⪧ ⪨ ⪩ ⪪ ⪫ ⪬ ⪭ ⪮ ⪯ ⪰ ⪱ ⪲ ⪳ ⪴ ⪵ ⪶ ⪷ ⪸ ⪹ ⪺ ⪻ ⪼ ⪽ ⪾ ⪿ ⫀ ⫁ ⫂ ⫃ ⫄ ⫅ ⫆ ⫇ ⫈ ⫉ ⫊ ⫋ ⫌ ⫍ ⫎ ⫏ ⫐ ⫑ ⫒ ⫓ ⫔ ⫕ ⫖ ⫗ ⫘ ⫙ ⫷ ⫸ ⫹ ⫺ ⊢ ⊣ ⟂ ⫪ ⫫ <: >: + - − ¦ | ⊕ ⊖ ⊞ ⊟ ++ ∪ ∨ ⊔ ± ∓ ∔ ∸ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⟇ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣ * / ⌿ ÷ % & · · ⋅ ∘ × \ ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗ ⨟ // ^ ↑ ↓ ⇵ ⟰ ⟱ ⤈ ⤉ ⤊ ⤋ ⤒ ⤓ ⥉ ⥌ ⥍ ⥏ ⥑ ⥔ ⥕ ⥘ ⥙ ⥜ ⥝ ⥠ ⥡ ⥣ ⥥ ⥮ ⥯ ↑ ↓ << >> >>>")],
SYNTACTIC_OPERATORS...)...)

# not really a const, but anyway
global _global_dataframe::Union{AbstractDataFrame, Nothing} = nothing
20 changes: 16 additions & 4 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ distinct(x::AbstractVector) = unique(x)
distinct(x::Base.SkipMissing) = distinct(collect(x))

"""
rowcount(x::AbstractVector) = length(collect(skipmissing(x)))
rowcount(x::AbstractVector) = length(keep_only_values(x))
Count the number of non-missing values in a vector.
Count the number of valid values in a vector.
"""
rowcount(x::AbstractVector) = length(collect(skipmissing(x)))
rowcount(x::AbstractVector) = length(keep_only_values(x))
rowcount(x::Base.SkipMissing) = length(collect(x))

tabulate(df::AbstractDataFrame, columns::Vector{Symbol}) = freqtable(df, columns...)

function summarize(df::AbstractDataFrame, column::Symbol)::Summarize
data = df[!, column] |> skipmissing |> collect
data = df[!, column] |> keep_only_values
n = length(data)
sum_val = sum(data)
mean_val = mean(data)
Expand Down Expand Up @@ -82,3 +82,15 @@ counter(gdf::GroupedDataFrame) = [nrow(df) for df in gdf]
Indicate that the function `f` should not be vectorized. The name DNV is only used for parsing, do not call it directly.
"""
DNV(args...; kwargs...) = error("This function should not be directly called. It is used to indicate that a function should not be vectorized. For example, @generate y = DNV(log(x))")

isvalue(x) = true
isvalue(::Missing) = false
isvalue(::Nothing) = false
isvalue(x::Number) = isinf(x) || isnan(x) ? false : true

"""
keep_only_values(x::AbstractVector) -> AbstractVector
Return a vector with only the values of `x`, excluding any `missing`` values, `nothing`s, `Inf`a and `NaN`s.
"""
keep_only_values(x) = filter(isvalue, collect(skipmissing(x)))
18 changes: 2 additions & 16 deletions src/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,19 @@ function construct_call(node::Node)
end

if node.type in [:&&, :||] && typeof(node.content) != Expr
return Expr(Symbol("." * String(node.type)), replace_logical_operators.(node.content)...)
return Expr(node.type, node.content...)
end

if typeof(node.content) == Expr
if node.type in [:&&, :||]
return Expr(Symbol("." * String(node.type)), node.content.args...)
return Expr(node.type, node.content.args...)
end
return node.content
end

return Expr(node.type, node.content...)
end

function replace_logical_operators(args)
if args in [:&&, :||]
return Symbol("." * String(args))
end
return args
end

function replace_logical_operators(args::Expr)::Expr
if args.head in [:&&, :||]
return Expr(Symbol("." * String(args.head)), replace_logical_operators.(args.args)...)
end
return args
end

function transition(state::Int64, arg::Node)::Int64
## from command to condition
if arg.content == Symbol("@if") && state == 1
Expand Down
10 changes: 5 additions & 5 deletions test/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ end
@test_expr vectorize_function_calls(:(div(x, y))) == :(div.(x, y))
@test_expr vectorize_function_calls(:(1 + div(x, y, z))) == :(1 .+ div.(x, y, z))
@testset "Do not vectorize" begin
@test_expr vectorize_function_calls(:(mean(x))) == :(mean(collect(skipmissing(x))))
@test_expr vectorize_function_calls(:(mean(x) + log(y))) == :(mean(collect(skipmissing(x))) .+ log.(y))
@test_expr vectorize_function_calls(:(mean(x))) == :(mean(keep_only_values(x)))
@test_expr vectorize_function_calls(:(mean(x) + log(y))) == :(mean(keep_only_values(x)) .+ log.(y))
@test_expr vectorize_function_calls(:(log.(x))) == :(log.(x))
@test_expr vectorize_function_calls(:(log(x) + sum(y))) == :(log.(x) .+ sum(collect(skipmissing(y))))
@test_expr vectorize_function_calls(:(wsum(x))) == :(wsum(collect(skipmissing(x))))
@test_expr vectorize_function_calls(:(std(x))) == :(std(collect(skipmissing(x))))
@test_expr vectorize_function_calls(:(log(x) + sum(y))) == :(log.(x) .+ sum(keep_only_values(y)))
@test_expr vectorize_function_calls(:(wsum(x))) == :(wsum(keep_only_values(x)))
@test_expr vectorize_function_calls(:(std(x))) == :(std(keep_only_values(x)))
end

@testset "Explicit DNV request" begin
Expand Down
15 changes: 15 additions & 0 deletions test/commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ end
@test df2.y == [4]
df2 = @with df @collapse y = mean(x)
@test df2.y == [2.0]
df2 = @with DataFrame(x=[1, Inf, 3]) @collapse y = sum(x)
@test df2.y == [4.0]
end
@testset "Vectorized does not collapse" begin
df = DataFrame(x=1:4, z= 5:8)
Expand Down Expand Up @@ -379,6 +381,8 @@ end
@testset "Complex conditions" begin
df2 = @with dfxz @egen y = sum(x) @if z == 4 && x > 2
@test all(df2.y .=== [missing, missing, missing, 4])
df2 = @with dfxz @egen y = sum(x) @if z == 4 && x > 2 && !ismissing(x)
@test all(df2.y .=== [missing, missing, missing, 4])
end
end

Expand Down Expand Up @@ -444,6 +448,17 @@ end
@test s.N == 2
@test s.mean == 2.0
end

@testset "Other NaN values" begin
df = DataFrame(x=[1, NaN, 3])
s = @with df @summarize x
@test s.N == 2
@test s.mean == 2.0
df = DataFrame(x=[1, Inf, 3])
s = @with df @summarize x
@test s.N == 2
@test s.mean == 2.0
end
end

@testset "Boolean-valued column" begin
Expand Down
4 changes: 2 additions & 2 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ TEST_CASES = [
(ex="@mockmacro x @if x < 0", command=:summarize, arguments=[:x], condition=:(x < 0), options=[]),
(ex="@mockmacro x @if ln(x) < 0", command=:summarize, arguments=[:x], condition=:(ln(x) < 0), options=[]),
(ex="@mockmacro x @if x < 0, detail", command=:summarize, arguments=[:x], condition=:(x < 0), options=[:detail]),
(ex="@mockmacro x @if x < 0 && y > 0", command=:summarize, arguments=[:x], condition=:(x < 0 .&& y > 0), options=[]),
(ex="@mockmacro x @if x < 0 && y > 0, detail", command=:summarize, arguments=[:x], condition=:(x < 0 .&& y > 0), options=[:detail]),
(ex="@mockmacro x @if x < 0 && y > 0", command=:summarize, arguments=[:x], condition=:(x < 0 && y > 0), options=[]),
(ex="@mockmacro x @if x < 0 && y > 0, detail", command=:summarize, arguments=[:x], condition=:(x < 0 && y > 0), options=[:detail]),
]


Expand Down

0 comments on commit 912c35a

Please sign in to comment.