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

InexactError when dealing with means of integers with missings #126

Open
eirikbrandsaas opened this issue Aug 24, 2022 · 3 comments · May be fixed by #172
Open

InexactError when dealing with means of integers with missings #126

eirikbrandsaas opened this issue Aug 24, 2022 · 3 comments · May be fixed by #172

Comments

@eirikbrandsaas
Copy link

a = [missing missing; 0 1]
mean(a;dims=2) # InexactError

The answer should be [missing, 0.5].

Note that

a = [missing missing; 1 1]
means(a;dims=2) # [missing 1]

works.

@pdeffebach
Copy link

Works with floats. I would guess some call to similar that isnt correct.

julia> b = [missing missing; 0.0 1.0]
2×2 Matrix{Union{Missing, Float64}}:
  missing   missing
 0.0       1.0

julia> mean(b, dims = 2)
2×1 Matrix{Union{Missing, Float64}}:
  missing
 0.5

@pdeffebach
Copy link

Error is this line

julia> Statistics._mean_promote(missing, 1)
1

julia> 1/1
1.0

julia> missing / 1
missing

The solution is probably to add more f(x) / 1 checks to get the output type right, since missing / 1 is not informative of what the output should be the same way 1/1 is. We could also add a skipmissing or something, though that is likely quite costly.

@nalimilan
Copy link
Member

See also #7.

@mbauman mbauman linked a pull request Aug 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants