8000 ENH: remove unneeded spaces in float/bool reprs, fixes 0d str by ahaldane · Pull Request #9139 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: remove unneeded spaces in float/bool reprs, fixes 0d str #9139

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

Merged
merged 6 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
ENH: "pad_sign" option, also threshold and edgeitems
  • Loading branch information
ahaldane committed Sep 26, 2017
commit b2d709a9630fcd83153aa7df17454d38a8c75534
29 changes: 23 additions & 6 deletions doc/release/1.14.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,27 @@ source to the destination.
Using field "titles" in multiple-field indexing is now disallowed, as is
repeating a field name in a multiple-field index.

Removed unneeded whitespace in float and bool array printing
``sign`` option added to ``np.setprintoptions`` and ``np.array2string``
-----------------------------------------------------------------------
This option controls printing of the sign of floating-point types, and may be
one of the characters '-', '+' or ' '. With '-' numpy only prints the sign of
negative values, with '+' it prints the sign of both negative an positive
values, and with ' ' it prints a space (whitespace character) in the sign
position of positive values, except in 0d arrays. The new default is '-'.
Copy link
Contributor

Choose a reason for hiding this comment

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

This got lost in time a bit for me, but was there a particular reason to have ' ' do something different for 0d arrays? Ideally, it is just the same... Especially, since then we can say we just implement the same as what CPython does for formatting numbers: https://docs.python.org/3/library/string.html#format-specification-mini-language
(indeed, I think we might as well refer to that here).


Unneeded whitespace in float and bool array printing removed
------------------------------------------------------------
The ``repr`` of float arrays now omits the whitespace character previsouly used
to display the sign if possible, for example if the array has all-positive
values. Similarly, the ``repr`` of bool arrays with only one element now omits
the whitespace before a ``True`` value, so that ``repr(array([True]))`` now
returns ``'array([True])'`` instead of ``'array([ True])'``.
The new default of ``sign='-'`` (see last note) means that the ``repr`` of
float arrays now often omits the whitespace character previously used to
display the sign. This new behavior can be disabled using the ``sign=' '``
option to ``np.set_printoptions`` described above, to mostly reproduce numpy
1.13 behavior.

Additionally, the ``repr`` of bool arrays with only one element now omits the
whitespace before a ``True`` value, so that ``repr(array([True]))`` now returns
``'array([True])'`` instead of ``'array([ True])'``.

``threshold`` and ``edgeitems`` options added to ``np.array2string``
-----------------------------------------------------------------
These options could previously be controlled using ``np.set_printoptions``, but
now can be changed on a per-call basis as arguments to ``np.array2string``.
Loading
0