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

Reword doc on undef arrays with missing #38260

Merged
merged 1 commit into from
Dec 4, 2020

Conversation

knuesel
Copy link
Member

@knuesel knuesel commented Nov 1, 2020

This is a follow-up to #31091. 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).

doc/src/manual/missing.md Outdated Show resolved Hide resolved
`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.
Due to implementation details, uninitialized arrays created with
Copy link
Member

Choose a reason for hiding this comment

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

maybe better say that this is the current behavior, but in general it should be treated as undefined for the purposes of the contract that the docstring gives. I thought this was your intention (with which I agree).

@nalimilan is probably better than me with suggesting a proper wording 😄.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, definitely better to emphasize the "undefined"-ness, hence undef, and that whatever is initialized shouldn't be relied on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that was my intention 😊

I wanted to avoid "currently" because it implies that the behavior might change, but it's precisely the part mentioned here that won't change according to Jeff. I didn't want the documentation to include something misleading... On the other hand, a permanent truth is currently true so "currently" is technically correct.

I also thought it was useful to mention "due to implementation details", otherwise the reader would think "then why the heck do they initialize these values!".

Here are two proposals:

    Due to implementation details, uninitialized arrays created with
    `Array{Union{Missing, T}}(undef, dims)` or with `similar` are actually
    filled with `missing` values in most cases where `T` is a bits type
    (`isbitstype(T)` returns `true`). However, this behavior is specific to
    `Base.Array` and is not reliable (it can fail when `T` is a singleton type).
    Values returned by `undef` constructors should be treated as undefined. Use
    a `missing` constructor as shown above to initialize values to `missing`.

and

    In the current implementation, uninitialized `Base` arrays as created with
    `Array{Union{Missing, T}}(undef, dims)` or with `similar` are actually
    filled with `missing` values in most cases where `T` is a bits type
    (`isbitstype(T)` returns `true`). This behavior should not be relied upon:
    values returned by `undef` constructors should be treated as undefined. Use
    a `missing` constructor as shown above to initialize values to `missing`.

I slightly prefer the second one. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

probably core devs should pick here 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

OK let's wait for their input then!

Copy link
Member

Choose a reason for hiding this comment

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

It should just say something like "using undef may currently give an array filled with missing, but this is not the correct way to obtain such an array. pass missing to the constructor instead." There's no need to mention bits types etc., it just confuses the issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

@JeffBezanson thanks for the feedback, I have updated the PR with a wording close to this.

@ViralBShah ViralBShah added the docs This change adds or pertains to documentation label Nov 10, 2020
@StefanKarpinski StefanKarpinski added the triage This should be discussed on a triage call label Nov 30, 2020
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).
@StefanKarpinski StefanKarpinski merged commit 2ced28b into JuliaLang:master Dec 4, 2020
@StefanKarpinski StefanKarpinski removed the triage This should be discussed on a triage call label Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants