10000 Add additional notes on longlong and Decimal(repr(scalar)) · numpy/numpy@6fdfffc · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fdfffc

Browse files
committed
Add additional notes on longlong and Decimal(repr(scalar))
1 parent 7912d35 commit 6fdfffc

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

doc/neps/nep-0051-scalar-representation.rst

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ with the new scheme to use the ``np`` prefix consistently:
5252
The NEP does not propose to change how these scalars print – only
5353
their representation (``__repr__``) will be changed.
5454
Further, array representation will not be affected since it already
55-
includes the ``dtype=`` when necessary.
55+
includes the ``dtype=`` when necessary.
5656

57-
The main motivation behind the change is that the Python numerical types
57+
The main motivation behind the change is that the Python numerical types
5858
behave differently from the NumPy scalars.
5959
For example numbers with lower precision (e.g. ``uint8`` or ``float16``)
6060
should be used with care and users should be aware when they are working
@@ -104,6 +104,14 @@ changes. In general we believe that informing users about the type
104104
they are working with outweighs the need for adapting printing in
105105
some instances.
106106

107+
The NumPy test suite includes code such as ``decimal.Decimal(repr(scalar))``.
108+
This code needs to be modified to use the ```str()``.
109+
110+
.. admonition:: TODO
111+
112+
If there is a lot of similar code, we may need a better solution than
113+
``str()``, since it is plausible that ``str()`` should honor
114+
107115
An exception to this are downstream libraries with documentation and
108116
especially documentation testing.
109117
Since the representation of many values will change, in many cases
@@ -136,7 +144,7 @@ This NEP proposes to change the represenatation for NumPy scalars to:
136144
``np.longdouble('3.0')``. This ensures that it can always roundtrip correctly
137145
and matches ``decimal.Decimal``.
138146
Further, for these two the size based name such as ``float128`` will not
139-
be adopted, as it is platform dependend and imprecise.
147+
be adopted, as it is platform dependend and imprecise.
140148
* ``np.str_("string")`` and ``np.bytes_(b"byte_string")`` for string dtypes.
141149

142150
Where booleans are printed as their singletons since this is more concise.
@@ -164,6 +172,24 @@ to always print as ``longdouble`` and never ``float128`` or ``float96``.
164172
It does not include deprecating the ``np.float128`` alias.
165173
However, such a deprecation may occur independently of the NEP.
166174

175+
Integer scalar type name and instance represenatation
176+
-----------------------------------------------------
177+
178+
One detail is that due to NumPy scalar types being based on the C types,
179+
NumPy sometimes distinguishes them, for example on most 64 bit systems
180+
(not windows)::
181+
182+
>>> np.longlong
183+
numpy.longlong
184+
>>> np.longlong(3)
185+
np.int64(3)
186+
187+
The proposal will lead to the ``longlong`` name for the type while
188+
using the ``int64`` form for the scalar.
189+
This choice is made since ``int64`` is generally the more useful
190+
information for users, but the type name itself must be precise.
191+
192+
167193
Related Work
168194
============
169195

0 commit comments

Comments
 (0)
0