From 3ae58e70d8aa48d1901960cd9f5acfb1d53cea12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 16 Feb 2019 13:10:26 +0100 Subject: [PATCH 1/4] Docs of construction undef arrays with missing This PR explains the behavior I observe, but it is not documented, so maybe it is not guaranteed (therefore before merging it should be confirmed that Base wants to guarantee this contract). The contract is that if `T` is a bits type then creation of uninitialized array of type `Union{Missing, T}` initializes it to hold `missing` in all entries. CC @nalimilan --- doc/src/manual/missing.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/src/manual/missing.md b/doc/src/manual/missing.md index 647434f4b7d25..a206d8164bd16 100644 --- a/doc/src/manual/missing.md +++ b/doc/src/manual/missing.md @@ -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 +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 From d4d8184e7a3b001b4a38c9056d37f7d2b6a9bd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 17 Feb 2019 21:14:46 +0100 Subject: [PATCH 2/4] change the description --- doc/src/manual/missing.md | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/doc/src/manual/missing.md b/doc/src/manual/missing.md index a206d8164bd16..ff18577c67604 100644 --- a/doc/src/manual/missing.md +++ b/doc/src/manual/missing.md @@ -254,22 +254,13 @@ 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 -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 - ``` +!!! note + Currently for `T` that is bits type (`isbitstype(T)` returns `true`), + `Array{Union{Missing, T}}(undef, dims)` creates an array filled with + 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. This behavior is an implementation detail + that may change in the future and should not be relied upon. 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 From f14bacc8db03bba1fac6effb104a3c02c50ce715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sat, 24 Oct 2020 12:09:14 +0200 Subject: [PATCH 3/4] Update doc/src/manual/missing.md --- doc/src/manual/missing.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/src/manual/missing.md b/doc/src/manual/missing.md index ff18577c67604..4c098173a3458 100644 --- a/doc/src/manual/missing.md +++ b/doc/src/manual/missing.md @@ -255,13 +255,13 @@ julia> Array{Union{Missing, String}}(missing, 2, 3) ``` !!! note - Currently for `T` that is bits type (`isbitstype(T)` returns `true`), - `Array{Union{Missing, T}}(undef, dims)` creates an array filled with - 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. This behavior is an implementation detail - that may change in the future and should not be relied upon. - + 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. 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 From eba5dc5d15ccab0979845b1f55333e6875ff72df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Sun, 25 Oct 2020 17:00:51 +0100 Subject: [PATCH 4/4] Update doc/src/manual/missing.md Co-authored-by: Milan Bouchet-Valat --- doc/src/manual/missing.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/src/manual/missing.md b/doc/src/manual/missing.md index 4c098173a3458..cb7676898d399 100644 --- a/doc/src/manual/missing.md +++ b/doc/src/manual/missing.md @@ -262,6 +262,7 @@ julia> Array{Union{Missing, String}}(missing, 2, 3) `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. + 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