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

DOC: Confusion about Boolean dtype #23366

Open
pauljurczak opened this issue Mar 9, 2023 · 3 comments · May be fixed by #24501
Open

DOC: Confusion about Boolean dtype #23366

pauljurczak opened this issue Mar 9, 2023 · 3 comments · May be fixed by #24501

Comments

@pauljurczak
Copy link

Issue with current documentation:

Page https://numpy.org/doc/stable/reference/arrays.dtypes.html recommends using ? to declare Boolean dtype and b for (signed) byte. Page https://numpy.org/doc/stable/reference/arrays.interface.html#arrays-interface recommends b for Boolean (integer type where all values are only True or False).

Idea or request for content:

Perhaps '?' boolean could be added to https://numpy.org/doc/stable/reference/arrays.interface.html#arrays-interface and meaning of b edited?

@seberg
Copy link
Member

seberg commented Mar 12, 2023

Its confusing, because 'b1' does denote boolean, because it is via the "kind" letters 'b', 'i', 'u', 'f', 'c', ... While ? is the single letter code where b would be byte (int8).

So the __array_interface__ is probably correct in that sense, but it seems all a bit unclear/managled up probably.

@pauljurczak
Copy link
Author

@seberg I didn't know about b1. It is a well hidden secret. It doesn't appear on any of the pages I linked. Full documentation search leads to a different meaning of b1: https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_EquivByteorders

dvorst added a commit to dvorst/numpy that referenced this issue Aug 22, 2023
Added documentation on boolean type ``b1`` which was previously not mentioned, causing confusion.
dvorst added a commit to dvorst/numpy that referenced this issue Aug 22, 2023
@dvorst
Copy link

dvorst commented Aug 22, 2023

Does this mean that the documentation of https://numpy.org/doc/stable/reference/arrays.dtypes.html is incomplete? Since it specifies: "The first character specifies the kind of data and the remaining characters specify the number of bytes per item", which would mean b -> int8 and 1 -> 1 byte. But b1 indicates a bool, so this dtype is specified by both the first letter as well as the number.

>>> numpy.dtype('?')
dtype('bool')
>>> numpy.dtype('b')
dtype('int8')
>>> numpy.dtype('b1')
dtype('bool')

Making a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants