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

Docs of construction undef arrays with missing #31091

Merged
merged 4 commits into from
Oct 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doc/src/manual/missing.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ julia> Array{Union{Missing, String}}(missing, 2, 3)
missing missing missing
```

For `T` that is bits type (`isbitstype(T)` returns `true`),
`Array{Union{Missing, T}}(undef, dims)` creates an array filled with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to recommend Array{Union{Missing, T}}(undef, dims) (which should work even for non-isbits T)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the problem. If T is non isbitstype then the array is truly uninitialized (#undef). If I understand the reason correctly this is for performance reasons.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean Array{Union{Missing, T}}(missing, dims) @fredrikekre?

I'm not sure whether it's a good idea to develop this here given that we want people to use Array{Union{Missing, T}}(missing, dims) rather than Array{Union{Missing, T}}(undef, dims), and that it makes things more complex with the introduction of the concept of isbits type. Maybe make this a shorter !!note without showing the REPL output? It would also be useful to mention for non-isbits type the entries will be #undef.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean...

Yea...

missing values. Also 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 bits type:
```jldoctest
julia> similar([1, missing])
2-element Array{Union{Missing, Int64},1}:
missing
missing

julia> similar([1, 2], Union{Missing, Float64})
2-element Array{Union{Missing, Float64},1}:
missing
missing
```

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
[`convert`](@ref). If the array contains `missing` values, a `MethodError` is thrown
Expand Down