8000 Merge pull request #10177 from eric-wieser/1.14-notes-update · numpy/numpy@5f01e54 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f01e54

Browse files
authored
Merge pull request #10177 from eric-wieser/1.14-notes-update
Final 1.14 formatting fixes
2 parents 1c86cdd + 4b49e99 commit 5f01e54

File tree

4 files changed

+66
-27
lines changed

4 files changed

+66
-27
lines changed

doc/release/1.14.0-notes.rst

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -253,37 +253,59 @@ enabling the new 1.13 "legacy" printing mode. This is enabled by calling
253253

254254
In summary, the major changes are:
255255

256-
* The ``repr`` of float arrays often omits a whitespace previously printed
257-
in the sign position. See the new ``sign`` option to ``np.set_printoptions``.
258-
* Floating-point arrays and scalars use a new algorithm for decimal
259-
representations, giving the shortest unique representation. This will
260-
usually shorten ``float16`` fractional output, and sometimes ``float32`` and
261-
``float128`` output. ``float64`` should be unaffected. See the new
262-
``floatmode`` option to ``np.set_printoptions``.
263-
* Float arrays printed in scientific notation no longer use fixed-precision,
264-
and now instead show the shortest unique representation.
265-
* The ``str`` of floating-point scalars is no longer truncated in python2.
266-
* Non-finite complex scalars print like ``nanj`` instead of ``nan*j``.
256+
* For floating-point types:
257+
258+
* The ``repr`` of float arrays often omits a space previously printed
259+
in the sign position. See the new ``sign`` option to ``np.set_printoptions``.
260+
* Floating-point arrays and scalars use a new algorithm for decimal
261+
representations, giving the shortest unique representation. This will
262+
usually shorten ``float16`` fractional output, and sometimes ``float32`` and
263+
``float128`` output. ``float64`` should be unaffected. See the new
264+
``floatmode`` option to ``np.set_printoptions``.
265+
* Float arrays printed in scientific notation no longer use fixed-precision,
266+
and now instead show the shortest unique representation.
267+
* The ``str`` of floating-point scalars is no longer truncated in python2.
268+
269+
* For other data types:
270+
271+
* Non-finite complex scalars print like ``nanj`` instead of ``nan*j``.
272+
* ``NaT`` values in datetime arrays are now properly aligned.
273+
* Arrays and scalars of ``np.void`` datatype are now printed using hex
274+
notation.
275+
276+
* For line-wrapping:
277+
278+
* The "dtype" part of ndarray reprs will now be printed on the next line
279+
if there isn't space on the last line of array output.
280+
* The ``linewidth`` format option is now always respected.
281+
The `repr` or `str` of an array will never exceed this, unless a single
282+
element is too wide.
283+
* All but the last line of array strings will contain the same number of
284+
elements.
285+
* The last line of an array string will never have more elements than earlier
286+
lines.
287+
288+
* For summarization (the use of ``...`` to shorten long arrays):
289+
290+
* A trailing comma is no longer inserted for ``str``.
291+
Previously, ``str(np.arange(1001))`` gave
292+
``'[ 0 1 2 ..., 998 999 1000]'``, which has an extra comma.
293+
* For arrays of 2-D and beyond, when ``...`` is printed on its own line in
294+
order to summarize any but the last axis, newlines are now appended to that
295+
line to match its leading newlines and a trailing space character is
296+
removed.
297+
267298
* ``MaskedArray`` arrays now separate printed elements with commas, always
268299
print the dtype, and correctly wrap the elements of long arrays to multiple
269300
lines. If there is more than 1 dimension, the array attributes are now
270301
printed in a new "left-justified" printing style.
271-
* ``NaT`` values in datetime arrays are now properly aligned.
272-
* Arrays and scalars of ``np.void`` datatype are now printed using hex notation.
302+
* ``recarray`` arrays no longer print a trailing space before their dtype, and
303+
wrap to the right number of columns.
273304
* 0d arrays no longer have their own idiosyncratic implementations of ``str``
274305
and ``repr``. The ``style`` argument to ``np.array2string`` is deprecated.
275306
* Arrays of ``bool`` datatype will omit the datatype in the ``repr``.
276-
* The "dtype" part of ndarray reprs will now be printed on the next line
277-
if there isn't space on the last line of array output.
278307
* User-defined ``dtypes`` (subclasses of ``np.generic``) now need to
279308
implement ``__str__`` and ``__repr__``.
280-
* The ``...`` used to summarize long arrays now omits a trailing comma for
281-
``str``. Previously, ``str(np.arange(1001))`` gave
282-
``'[ 0 1 2 ..., 998 999 1000]'``, which has an extra comma.
283-
* When a summarization ``...`` would be printed on its own line, e.g., for
284-
summarization along any ndarray dimension but the last, a trailing
285-
whitespace is now removed and trailing newlines added to match
286-
the leading newlines.
287309

288310
Some of these changes are described in more detail below.
289311

numpy/core/records.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from . import numeric as sb
4343
from . import numerictypes as nt
4444
from numpy.compat import isfileobj, bytes, long
45+
from .arrayprint import get_printoptions
4546

4647
# All of the functions allow formats to be a dtype
4748
__all__ = ['record', 'recarray', 'format_parser']
@@ -525,22 +526,25 @@ def __repr__(self):
525526
if repr_dtype.type is record:
526527
repr_dtype = sb.dtype((nt.void, repr_dtype))
527528
prefix = "rec.array("
528-
fmt = 'rec.array(%s, %sdtype=%s)'
529+
fmt = 'rec.array(%s,%sdtype=%s)'
529530
else:
530531
# otherwise represent it using np.array plus a view
531532
# This should only happen if the user is playing
532533
# strange games with dtypes.
533534
prefix = "array("
534-
fmt = 'array(%s, %sdtype=%s).view(numpy.recarray)'
535+
fmt = 'array(%s,%sdtype=%s).view(numpy.recarray)'
535536

536537
# get data/shape string. logic taken from numeric.array_repr
537538
if self.size > 0 or self.shape == (0,):
538-
lst = sb.array2string(self, separator=', ', prefix=prefix)
539+
lst = sb.array2string(
540+
self, separator=', ', prefix=prefix, suffix=',')
539541
else:
540542
# show zero-length shape unless it is (0,)
541543
lst = "[], shape=%s" % (repr(self.shape),)
542544

543545
lf = '\n'+' '*len(prefix)
546+
if get_printoptions()['legacy'] == '1.13':
547+
lf = ' ' + lf # trailing space
544548
return fmt % (lst, lf, repr_dtype)
545549

546550
def field(self, attr, val=None):

numpy/core/tests/test_records.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ def test_recarray_from_obj(self):
101101
assert_((mine.data1[i] == 0.0))
102102
assert_((mine.data2[i] == 0.0))
103103

104+
def test_recarray_repr(self):
105+
a = np.array([(1, 0.1), (2, 0.2)],
106+
dtype=[('foo', int), ('bar', float)])
107+
a = np.rec.array(a)
108+
assert_equal(
109+
repr(a),
110+
textwrap.dedent("""\
111+
rec.array([(1, 0.1), (2, 0.2)],
112+
dtype=[('foo', '<i4'), ('bar', '<f8')])""")
113+
)
114+
104115
def test_recarray_from_repr(self):
105116
a = np.array([(1,'ABC'), (2, "DEF")],
106117
dtype=[('foo', int), ('bar', 'S4')])

numpy/ma/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3937,11 +3937,13 @@ def __repr__(self):
39373937
reprs['data'] = np.array2string(
39383938
self._insert_masked_print(),
39393939
separator=", ",
3940-
prefix=indents['data'] + 'data=')
3940+
prefix=indents['data'] + 'data=',
3941+
suffix=',')
39413942
reprs['mask'] = np.array2string(
39423943
self._mask,
39433944
separator=", ",
3944-
prefix=indents['mask'] + 'mask=')
3945+
prefix=indents['mask'] + 'mask=',
3946+
suffix=',')
39453947
reprs['fill_value'] = repr(self.fill_value)
39463948
if dtype_needed:
39473949
reprs['dtype'] = np.core.arrayprint.dtype_short_repr(self.dtype)

0 commit comments

Comments
 (0)
0