Skip to content

Commit eb80aec

Browse files
authored
Merge pull request #453 from numpy/docs/longdouble-item-differences
📝 document the differences between the longdouble `item` and `tolist` methods
2 parents 44b9341 + 5e4e05a commit eb80aec

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

docs/user_guide/differences.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,30 @@ The following non-existent scalar types have been removed (numpy/numtype#209):
151151

152152
These types will not be defined on any supported platform.
153153

154-
## Aliases of `longdouble`
154+
## Aliases of `[c]longdouble`
155155

156156
The platform-dependent `float96` and `float128` types are equivalent aliases of
157157
`longdouble` (numpy/numtype#397):, and their complex analogues, `complex192` and `complex256`,
158158
alias `clongdouble` (numpy/numtype#391).
159159
This was done in order to minimize the expected amount of "but it works on my machine".
160160

161+
## Return types of `[c]longdouble.item()` and `.tolist()`
162+
163+
In Numpy, `longdouble` and `clongdouble` aren't annotated as concrete subclasses of
164+
`[complex]floating`, but as *aliases*. A consequence of this is that their `item` and `tolist`
165+
methods had to return the same type as that of all other `floating` and `complexfloating` types,
166+
i.e. `float` and `complex`. But this is incorrect for `longdouble` and `clongdouble`:
167+
168+
```pycon
169+
>>> import numpy as np
170+
>>> np.longdouble(1).item()
171+
np.longdouble('1.0')
172+
>>> np.clongdouble(1).item()
173+
np.clongdouble('1+0j')
174+
```
175+
176+
In NumType, the stubs correctly reflect this runtime behaviour.
177+
161178
## Removed `number.__floordiv__`
162179

163180
The abstract `numpy.number` type represents a scalar that's either integer, float, or complex.

0 commit comments

Comments
 (0)