Skip to content

Commit

Permalink
Reword doc on undef arrays with missing (JuliaLang#38260)
Browse files Browse the repository at this point in the history
The intent is to make clear that undef constructors are not the right
way to initialize arrays to missing. This way, other array
implementations (such as SentinelArrays.jl) are free to provide faster
undef constructors that actually leave data uninitialized (without
creating an incompatiblity with specified behavior from Base).
  • Loading branch information
knuesel authored Dec 4, 2020
1 parent dc38a37 commit 2ced28b
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions doc/src/manual/missing.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,9 @@ julia> Array{Union{Missing, String}}(missing, 2, 3)
```

!!! note
Currently for `T` that is bits type (`isbitstype(T)` returns `true`), if `T`
is not a singleton type then `Array{Union{Missing, T}}(undef, dims)` creates
an array filled with `missing` values. Also in this case calling `similar`
to create an unitialized array that has element type of the form
`Union{Missing, T}` creates an array filled with `missing`. If `T` is a
singleton type the value that is used to fill the array is undefined and
could change in the future, so it should not be relied upon.
Using `undef` or `similar` may currently give an array filled with
`missing`, but this is not the correct way to obtain such an array.
Use a `missing` constructor as shown above instead.

An array allowing for `missing` values but which does not contain any such value
can be converted back to an array which does not allow for missing values using
Expand Down

0 comments on commit 2ced28b

Please sign in to comment.