# Why are missing values not ignored by default?

**URL:** <https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756>\
**Category:** Internals & Design\
**Tags:** data, missing-values\
**Created:** [November 26, 2023, 1:45am UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756 "2023-11-26T01:45:36Z")\
**Posts on this page:** 20\
**Page:** 6

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 28, 2023, 2:06pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/103 "2023-11-28T14:06:47Z")

</div>

> [@Raf](#):
>
> It was heavily outvoted in discussion, if hearts count for anything. So from this small survey it seems people don’t actually share that opinion

1. not all those hearts are from data scientists 2. data scientists overwhelmingly don’t use Julia in the first place (perhaps in part because they don’t want to write `skipmissing` 100 times a day?), so I think the heart count is a complete non-sequitur to my assertion

> And its a breaking change, so its not going to happen

this part is true, very unfortunately.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [November 28, 2023, 3:12pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/104 "2023-11-28T15:12:13Z")

</div>

> [@adienes](#):
>
> data scientists overwhelmingly don’t use Julia in the first place (perhaps in part because they don’t want to write `skipmissing` 100 times a day?),

Compared to the size of the Python user base, nobody uses Julia.

On the other hand I specifically use Julia for data analysis for a number of reasons, the first one is that DataFrames and DataFramesMeta are just vastly superior to the tidyverse and its intense reliance on fexpr which is ultimately incredibly unusable for anyone who isn’t a naive non-programmer (ie. For actual programmers). The second is that Julia itself is fast and I can write simulations directly in Julia that run 100x faster than R or Python. The third is that Julia developers come from a consistent point of view that I agree with and one of those points of view is that you never silently change the meaning of stuff under the hood.

In Julia, If you want to change the meaning of stuff we have an explicit mechanism… Macros, which rewrite code. If something is supposed to have a special meaning it gets called out with the `@` symbol. This is tremendously helpful for understanding what code does.

The benefit of macros over fexpr was hashed out 40 years ago [``Special Forms in Lisp'' by Kent Pitman (August, 1980)](http://nhplace.com/kent/Papers/Special-Forms.html) I think Kent was right, and R/tidyverse is demonstrably wrong.

Another thing I think is demonstrably wrong is a system that silently ignores missing values rather than explicitly ignores them when specifically told. This is why `na.rm=F` is the default in R. Julia and R are both correct about this.

On the other hand, I acknowledge that if you want to write a block of code where you always ignore missing, then it would be annoying to have to type skipmissing each time.

Enter Julia’s explicit mechanism for this… The Macro! I don’t have a macro written but with MacroTools.jl it should be a few tens of lines to write an `@skipm` macro to insert skipmissing into all arguments of the functions listed in a given list of functions.

`@skipm funcs expr`

With perhaps a default set of funcs so you can leave that out most of the time.

Candidates for funcs might be things like  
`[:mean, :sum, :median,:quantile,:>,:<,:==]`

I’m sure you can think of more…

This is the **explicit** mechanism that Julia has created to enable you to change the meaning of code. That’s what macros do, they alter the semantics of code by transforming it to other code. This is explicitly one of the reasons I use Julia because it gets this right!

My suspicion is that @adienes doesn’t know macro programming. This isn’t intended as a dig or denigration or anything. It’s just that if he knew macro programming he’d probably have just written the macro! So this is a great opportunity to dig into macro programming, because it’s the exact mechanism that Julia creates for solving this problem!

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [November 28, 2023, 3:26pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/105 "2023-11-28T15:26:03Z")

</div>

> [@adienes](#):
>
> data scientists overwhelmingly don’t use Julia in the first place (perhaps in part because they don’t want to write `skipmissing` 100 times a day?)

It would be helpful if you could provide specific examples in R or Python where missing handling is better than in Julia.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 28, 2023, 3:35pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/106 "2023-11-28T15:35:32Z")

</div>

in polars:

```julia
df.select(pl.corr(col1, col2))

```

vs in Julia you have to write your own

```julia
function missing_cor(a,b)
    mask = (!).(ismissing.(a) .|| ismissing.(b))
    cor(a[mask], b[mask])
end

combine(df, [:col1, :col2] => missing_cor)

```

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [November 28, 2023, 4:24pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/107 "2023-11-28T16:24:30Z")

</div>

Stealing directly from Bogumil’s [blog](https://bkamins.github.io/julialang/2022/06/17/missing.html), there is already a somewhat nice interface for this in StatsBase:

```julia
julia> using Statistics, StatsBase

julia> df = DataFrame(x=[1, missing, 3, 4], y = [4, 3, missing, 1])
4×2 DataFrame
 Row │ x y
     │ Int64? Int64?
─────┼──────────────────
   1 │ 1 4
   2 │ missing 3
   3 │ 3 missing
   4 │ 4 1

julia> pairwise(cor, eachcol(df), skipmissing=:pairwise)
2×2 Matrix{Float64}:
  1.0 -1.0
 -1.0 1.0

```

Another option is to use `skipmissings` from Missings.jl:

```julia
julia> x=[1, missing, 3, 4]; y = [4, 3, missing, 1];

julia> smx, smy = skipmissings(x, y);

julia> cor(collect(smx), collect(smy))
-1.0

```

Note that Polars currently doesn’t even give you the option of propagating missing values in `pl.corr`, so if you wanted propagation by default for safety, then you would be out of luck. (I often don’t realize that I have missing values in some columns until I get a missing result from a calculation.)

Base Julia provides the foundations for handling missing values. And I think Base Julia made the correct decision by following the three-valued logic that R and SQL use. It’s perfectly feasible for Base Julia and packages to build on that foundation to make missing value handling as ergonomic as possible. We already have some of that with the following:

- `Base.coalesce`
- `Base.skipmissing`
- `Missings.passmissing`
- `Missings.skipmissings`
- `StatsBase.pairwise`
- `DataFrames.subset(...; skipmissing=true)`
- `DataFramesMeta.@subset(...)`

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [November 28, 2023, 5:19pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/108 "2023-11-28T17:19:05Z")

</div>

> [@alfaromartino](#):
>
> ```julia
> isnonnegative(a,b) = (ismissing(a) == 0) && (a >= b)
> df.col3 = df.col2[isnonnegative.(df.col2, 0), :]
> df.col4 = mean(skipmissing(df.col3))
> 
> ```

Let’s focus on the filtered mean. Sticking to Base Julia, the above can be rewritten in one line by using [`coalesce`](https://docs.julialang.org/en/v1/base/base/#Base.coalesce). First, let me define the input vector:

```julia
x = [-1, missing, 1, 2]

```

Now we just need one line of code:

```julia
mean(x[coalesce.(x .≥ 0, false)])

```

If you want to use DataFrames, you can use `subset` with the `skipmissing` keyword argument, like this:

```julia
# Input:
df = DataFrame(x=[-1, missing, 1, 2])

# Analysis code:
dfsub = subset(df, :x => ByRow(≥(0)); skipmissing=true)
mean(dfsub.x)

```

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 28, 2023, 5:24pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/109 "2023-11-28T17:24:39Z")

</div>

I do not doubt that Julia has any capability needed if the user is willing to type a little more. it is just clearly a debate about whether or not the “safety” is worth the “clunkiness”

(in fact, I think status quo is neither “safer” nor necessarily “clunky”, so I am just using the words to be generous to both viewpoints)

to me, the answer to that question is it is absolutely not worth, but to others apparently it is

I am not sure how much farther we can go in this debate since it is almost purely personal preference and Julia has already planted the flag down on its existing semantics. I just get prickly when my preferred behavior is referred to as “wrong,” “unsafe,” “negligent,” etc. because I strongly feel that it is none of those things; it is just a different _design choice_ is all

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [November 28, 2023, 5:27pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/110 "2023-11-28T17:27:15Z")

</div>

There is the following option:

```julia
cor(eachcol(dropmissing(df2[!,[:x1,:x2]]; view=true))...)

```

which is used in:

```julia
julia> using Random; Random.seed!(10);

julia> df2 = DataFrame([rand() < 0.3 ? missing : rand() for i in CartesianIndices((10,3))], :auto)
10×3 DataFrame
 Row │ x1 x2 x3             
     │ Float64? Float64? Float64?       
─────┼───────────────────────────────────────────────────
   1 │ 0.0876651 0.85494 0.89628
   2 │ missing missing missing        
   3 │ missing 0.210642 0.80741
   4 │ 0.536775 0.93207 0.759976
   5 │ 0.607473 0.00306044 missing        
   6 │ 0.574958 0.184803 0.760385
   7 │ 0.0317978 missing 0.727141
   8 │ missing 0.00605547 0.580357
   9 │ missing missing missing        
  10 │ 0.0523389 0.597275 missing        

julia> cor(eachcol(dropmissing(df2[!,[:x1,:x2]]; view=true))...)
-0.5343481606122596

```

Not taking any side strongly. But it is very similar to other tradeoffs, such as Int overflow, view vs. copy, bounds checking. Solving these issues needs a careful tread or maybe even a benevolent decider.

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [November 28, 2023, 5:59pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/111 "2023-11-28T17:59:29Z")

</div>

> [@adienes](#):
>
> I am not sure how much farther we can go in this debate since it is almost purely personal preference and Julia has already planted the flag down on its existing semantics.

I don’t want to drag this out, but can we at least agree that `missing` should propagate through comparison operators? That is what R, SQL, and Polars all do. Here is a Polars example:

```python
In [10]: df = pl.DataFrame({"x": [42, None]})

In [11]: df.with_columns(y = pl.col("x") >= 0)
Out[11]:
shape: (2, 2)
┌──────┬──────┐
│ x ┆ y │
│ --- ┆ --- │
│ i64 ┆ bool │
╞══════╪══════╡
│ 42 ┆ true │
│ null ┆ null │
└──────┴──────┘

In [12]: df.with_columns(y = pl.col("x") >= 0).filter("y")
Out[12]:
shape: (1, 2)
┌─────┬──────┐
│ x ┆ y │
│ --- ┆ --- │
│ i64 ┆ bool │
╞═════╪══════╡
│ 42 ┆ true │
└─────┴──────┘

```

Given that missing values should propagate through comparison operators, it makes sense that the skipping of missing values (returned by predicates) should happen during the filtering step. That is how it works in SQL, Polars, dplyr, and `DataFrames.subset(...; skipmissing=true)`.

(I mean, if you are doing a filtering… Obviously sometimes you aren’t doing a filter.)

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 28, 2023, 6:03pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/112 "2023-11-28T18:03:24Z")

</div>

yes, we agree on that.

I think it got a little lost in the long thread, but I still currently stand by this one:

> [@Why are missing values not ignored by default?](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/64):
>
> there has to be somewhere to [draw the line](https://jle.aals.org/cgi/viewcontent.cgi?article=1715&context=home) ; not every function can propagate missing, but you raise good arguments as to why some of them should with that being said, I think my ideal world would be: binary operators propagate, statistical moments and quantiles (and cor and cov) skip, everything else MethodError, so mean(heights .\> 5.5) would work just fine

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [November 28, 2023, 6:14pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/113 "2023-11-28T18:14:54Z")

</div>

I would be in favor of adding skip-missing versions of Base aggregation functions to Missings.jl, e.g. `smean`, `ssum`, etc. They’re commonly enough needed that it would be nice to have them at your fingertips with a simple `using Missings`.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [November 28, 2023, 6:34pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/114 "2023-11-28T18:34:14Z")

</div>

Perhaps it is time for a poll. Someone who has read this thread from the beginning, can make a question with possible solutions, or a couple of question (at most), and we can see where people stand.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [November 28, 2023, 7:06pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/115 "2023-11-28T19:06:36Z")

</div>

There is a difference between changing the API at its root for everyone and changing the APIs for preference.

I’m still very confused why the majority of the conversation here is about changing some established API whereas Julia gives the user many facilities to customize the API both through packages and at the user level.

> [@alfaromartino](#):
>
> The example also shows that the only potential solution is Julia 2.0 to add a new type of missing specialized for data analysis. But this would require DataFrames adopting it, which requires a lot of work and agreement about what the community thinks the default behavior should be.
> 
> Using macros or shortening the name doesn’t solve the problem, because it’s not about `skipmissing` as the example shows. It’s how missing are treated structurally.  
> Also, shortening names of functions is not desirable. I prefer that new users read `skipmissing` and know what that means, rather than wondering what `sm` means (e.g., R with their `na.rm`).

I’m particularly concerned about these comments. The Julia 2 reference is really a fanciful distraction. In reality, it is probably quite far away and ultimately will likely not contain the changes that you want. My expectation for Julia 2 is that it will only introduce some minor but really important breaking changes but keep functioning as is for the large majority of Julia 1 code.

More importantly, I’m not particularly convinced that this requires a breaking change to Julia or a fundamental change to how any of the packages mentioned work.

There are two approaches to customizing the API.

1. Shadow the functions
2. Introduce new types

## Introducing new functions to shadow existing APIs

I’ve shown examples about how methods can be shadowed above. Essentially, this is reminiscent about how things are in Python. We emulate APIs by placing similarly named APIs in distinct namespaces. This is often discouraged in Julia because it by itself does not compose as well. However, it is significantly simpler and creates less risk of introducing compilation related issues such as invalidation. We can actually have it both ways in Julia by having core packages which implement their own APIs in separate namespaces and separate packages which overload `Base` methods and forward to the namedspaced versions.

> [@CameronBieganek](#):
>
> I would be in favor of adding skip-missing versions of Base aggregation functions to [Missings.jl](https://juliahub.com/ui/Packages/Missings), e.g. `smmean`, `smsum`, etc. They’re commonly enough needed that it would be nice to have them at your fingertips with a simple `using Missings`.

Instead of mangling the name, why not just scope them into the module. They could be `sm.mean` and `sm.sum`? We could actually do both approaches. There could be a submodule that is meant for scoped names and another one with prefixed names, both pointing to the same underlying implementation.

## Using Types to Modify the API

There are a few ways to introduce new types in order to customize an API. The one that seems to have been discussed above is to introduce a new kind of `Missing`. For `UnsafeMissing` I just want to point out that it is completely possible to implement that in a package.

Another approach for introducing new types is to create wrappers. In this example, we could wrap a `DataFrame` in order the change the behavior. This in turn could returned wrapped columns, which return wrapped or replaced `missing` values when indexed. This would allow us to effectively overlay our API preferences over the existing API.

Here’s an lightweight example of this.

> **Setup Code**
>
> ```julia
> julia> using CSV, DataFrames, Statistics
> 
> julia> struct SkipMissingDataFrame
> parent::DataFrame
> end
> 
> julia> Base.parent(smdf::SkipMissingDataFrame) = getfield(smdf, :parent)
> 
> julia> Base.getproperty(smdf::SkipMissingDataFrame, sym::Symbol) = skipmissing(Base.getproperty(parent(smdf), sym))
> 
> julia> write("blah.csv","""
> "col1", "col2"
> "5", "6"
> "1", "2"
> "30", "31"
> "22", "23"
> "NA"
> "50"
> """)
> 65
> 
> ```

```julia
julia> df = CSV.read("blah.csv", DataFrame; silencewarnings=true);
julia> smdf = SkipMissingDataFrame(df)
SkipMissingDataFrame(6×2 DataFrame
 Row │ col1 col2    
     │ String3 Int64?  
─────┼──────────────────
   1 │ 5 6
   2 │ 1 2
   3 │ 30 31
   4 │ 22 23
   5 │ NA missing 
   6 │ 50 missing )

julia> smdf.col2 |> mean
15.5

julia> smdf.col2 |> x->Iterators.filter(>(10),x) |> mean
27.0

```

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [November 28, 2023, 7:21pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/116 "2023-11-28T19:21:13Z")

</div>

> [@mkitti](#):
>
> Instead of mangling the name, why not just scope them into the module. They could be `sm.mean` and `sm.sum`?

We can of course bikeshed the name. To me, the name `sm.mean` looks like a property access on an object, so it should be `SM.mean`. But that looks ugly. 🙂

It seems like the main objection to `mean(skipmissing(x))` is that it is too verbose and too many keystrokes, so let’s make the abbreviation as short as possible:

- `smean`
- `ssum`
- `svar`
- `scor`

I’ve opened an issue here:

> <https://github.com/JuliaData/Missings.jl/issues/146>
>
> xref: https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-de…fault/106756
> 
> There are some users who dislike \`mean(skipmissing(x))\` because they view it as too verbose or too many keystrokes. Aggregation functions that skip missing values are very commonly needed, so I think it would be worth adding convenience skip-missing methods for Base aggregation functions to Missings.jl, e.g.
> 
> \- \`smean\`
> \- \`ssum\`
> \- \`svar\`
> \- \`scor\`
> 
> The \`svar\` and \`scor\` functions could have a keyword argument to control exactly how missing values are skipped, similar to \[\`cor\` in R\](https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/cor).

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [November 28, 2023, 7:28pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/117 "2023-11-28T19:28:19Z")

</div>

My thought is what if they just want `mean` to just be `Missings.smean`? I suppose they could do `const mean = smean` or `using Missings.smean as mean`.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [November 28, 2023, 7:30pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/118 "2023-11-28T19:30:00Z")

</div>

The really nice affordance that @mkitti is suggesting is that you can write `using SkipMissings: mean` at the very beginning and then it will _shadow_ `mean` for the code you write.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 28, 2023, 7:32pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/119 "2023-11-28T19:32:23Z")

</div>

`smean` seems fine as long as it is as performant and stable as `Base.mean` (which is currently not the case). `cor` and `cov` are the more painful cases so `scor` and `scov` more badly needed

I made the issue in `DataFrames.jl` here a few weeks ago [feature request: allow `skipmissing` column types · Issue #3398 · JuliaData/DataFrames.jl · GitHub](https://github.com/JuliaData/DataFrames.jl/issues/3398)

since an alternate approach would be to allow columns to be of type `SkipMissing`, and then I could call `skipmissing!(df)` , analogous to the existing `allowmissing!(df)` and all aggregations would have the behavior I want

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 28, 2023, 7:42pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/120 "2023-11-28T19:42:56Z")

</div>

I think `import SM: mean` and then seeing, 100 lines down

```julia
mean(x)

```

is definitely code-smell. It’s not good to have different behavior so far from the call-site. I think a better scenario is `skip(mean)(x)`. Where `skip` wraps a function and does pre-processing on `x` to ensure `missing`s ar skipped. This has the benefits of not requiring re-writing lots of function definitions.

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [November 28, 2023, 7:47pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/121 "2023-11-28T19:47:33Z")

</div>

> [@mbauman](#):
>
> The really nice affordance that @mkitti is suggesting is that you can write `using SkipMissings: mean` at the very beginning and then it will _shadow_ `mean` for the code you write.

I’m not convinced that’s a good idea. It goes against the spirit of generic programming in Julia. The `mean` and `smean` functions are fundamentally different functions.

> [@pdeffebach](#):
>
> I think a better scenario is `skip(mean)(x)`.

That’s not much different from `mean(skipmissing(x))`. Again, I think we want to go for the absolute minimum amount of typing, hence `smean`. Minimizing typing and verbosity is the main goal of these shortcut functions.

Also, as @adienes mentioned, the simplification provided by `scor` and `svar` is a big win. I’m not sure if `skip(cor)(x)` could provide that… maybe `skip(cor; skipmissing=:pairwise)(x, y)`, but that seems awkward.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 28, 2023, 7:52pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/122 "2023-11-28T19:52:27Z")

</div>

`skip(cor)` would indeed provide that. See [here](https://github.com/JuliaData/Missings.jl/pull/122)

[Previous page](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756.md?page=5)

[Next page](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756.md?page=7)
