8000 DOC: Update reference to pass refguide · numpy/numpy@387e26a · GitHub
[go: up one dir, main page]

Skip to content

Commit 387e26a

Browse files
committed
DOC: Update reference to pass refguide
This makes things pass even though there should be a massive amount of types added in other places, so that it is not complete. But I think this may be useful, since the complete change would be quite verbose... One thing to note may be that `np.float64(nan)` currently does not round-trip correctly of course, this would require adding `np.` to the repr (or quotes).
1 parent a7510a9 commit 387e26a

9 files changed

+32
-35
lines changed

numpy/core/_add_newdocs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4670,7 +4670,7 @@
46704670
46714671
>>> x[0] = (9, 10)
46724672
>>> z[0]
4673-
(9, 10)
4673+
np.record((9, 10), dtype=[('a', 'i1'), ('b', 'i1')])
46744674
46754675
Views that change the dtype size (bytes per entry) should normally be
46764676
avoided on arrays defined by slices, transposes, fortran-ordering, etc.:

numpy/core/_add_newdocs_scalars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ def add_newdoc_for_scalar_type(obj, fixed_aliases, doc):
228228
Either an opaque sequence of bytes, or a structure.
229229
230230
>>> np.void(b'abcd')
231-
void(b'\x61\x62\x63\x64')
231+
np.void(b'\x61\x62\x63\x64')
232232
233233
Structured `void` scalars can only be constructed via extraction from :ref:`structured_arrays`:
234234
235235
>>> arr = np.array((1, 2), dtype=[('x', np.int8), ('y', np.int8)])
236236
>>> arr[()]
237-
(1, 2) # looks like a tuple, but is `np.void`
237+
np.void((1, 2), dtype=[('x', 'i1'), ('y', 'i1')])
238238
""")
239239

240240
add_newdoc_for_scalar_type('datetime64', [],

numpy/core/_ufunc_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class errstate(contextlib.ContextDecorator):
409409
array([nan, inf, inf])
410410
411411
>>> np.sqrt(-1)
412-
nan
412+
np.float64(nan)
413413
>>> with np.errstate(invalid='raise'):
414414
... np.sqrt(-1)
415415
Traceback (most recent call last):

numpy/core/fromnumeric.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,7 +2796,7 @@ def amax(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
27962796
>>> b = np.arange(5, dtype=float)
27972797
>>> b[2] = np.NaN
27982798
>>> np.amax(b)
2799-
nan
2799+
np.float64(nan)
28002800
>>> np.amax(b, where=~np.isnan(b), initial=-1)
28012801
4.0
28022802
>>> np.nanmax(b)
@@ -2923,7 +2923,7 @@ def amin(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
29232923
>>> b = np.arange(5, dtype=float)
29242924
>>> b[2] = np.NaN
29252925
>>> np.amin(b)
2926-
nan
2926+
np.float64(nan)
29272927
>>> np.amin(b, where=~np.isnan(b), initial=10)
29282928
0.0
29292929
>>> np.nanmin(b)

numpy/core/src/multiarray/scalartypes.c.src

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,8 @@ legacy_@name@_format@kind@(npy_@name@ val){
958958
* # 6D40 Name = Float, Double, LongDouble#
959959
* #NAME = FLOAT, DOUBLE, LONGDOUBLE#
960960
* #repr_format = np.float32(%S), np.float64(%S), np.longdouble('%S')#
961-
* #crepr_format = np.complex64(%S), np.complex128(%S), np.clongdouble('%S')#
961+
* #crepr_format = np.complex64(%S%Sj), np.complex128(%S%Sj),
962+
* np.clongdouble('%S%Sj')#
962963
*/
963964

964965
/* helper function choose scientific of fractional output, based on a cutoff */
@@ -1052,17 +1053,14 @@ c@name@type_@kind@(PyObject *self)
10521053
return NULL;
10531054
}
10541055

1056+
#ifdef IS_str
10551057
PyObject *string = PyUnicode_FromFormat("(%S%Sj)", rstr, istr);
1056-
Py_DECREF(rstr);
1057-
Py_DECREF(istr);
1058-
1059-
#ifdef IS_repr
1060-
if (string == NULL) {
1061-
return NULL;
1062-
}
1063-
Py_SETREF(string, PyUnicode_FromFormat("@crepr_format@", string));
1058+
#else /* IS_repr */
1059+
PyObject *string = PyUnicode_FromFormat("@crepr_format@", rstr, istr);
10641060
#endif /* IS_repr */
10651061

1062+
Py_DECREF(rstr);
1063+
Py_DECREF(istr);
10661064
return string;
10671065
}
10681066

numpy/lib/nanfunctions.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,9 @@ def nansum(a, axis=None, dtype=None, out=None, keepdims=np._NoValue,
713713
>>> np.nansum([1, np.nan, np.NINF])
714714
-inf
715715
>>> from numpy.testing import suppress_warnings
716-
>>> with suppress_warnings() as sup:
717-
... sup.filter(RuntimeWarning)
716+
>>> with np.errstate(invalid="ignore"):
718717
... np.nansum([1, np.nan, np.inf, -np.inf]) # both +/- infinity present
719-
nan
718+
np.float64(nan)
720719
721720
"""
722721
a, mask = _replace_nan(a, 0)
@@ -1191,7 +1190,7 @@ def nanmedian(a, axis=None, out=None, overwrite_input=False, keepdims=np._NoValu
11911190
array([[10., nan, 4.],
11921191
[ 3., 2., 1.]])
11931192
>>> np.median(a)
1194-
nan
1193+
np.float64(nan)
11951194
>>> np.nanmedian(a)
11961195
3.0
11971196
>>> np.nanmedian(a, axis=0)
@@ -1344,7 +1343,7 @@ def nanpercentile(
13441343
array([[10., nan, 4.],
13451344
[ 3., 2., 1.]])
13461345
>>> np.percentile(a, 50)
1347-
nan
1346+
np.float64(nan)
13481347
>>> np.nanpercentile(a, 50)
13491348
3.0
13501349
>>> np.nanpercentile(a, 50, axis=0)
@@ -1504,7 +1503,7 @@ def nanquantile(
15041503
array([[10., nan, 4.],
15051504
[ 3., 2., 1.]])
15061505
>>> np.quantile(a, 0.5)
1507-
nan
1506+
np.float64(nan)
15081507
>>> np.nanquantile(a, 0.5)
15091508
3.0
15101509
>>> np.nanquantile(a, 0.5, axis=0)

numpy/lib/recfunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ def stack_arrays(arrays, defaults=None, usemask=True, asrecarray=False,
12681268
mask=[(False, False, True), (False, False, True),
12691269
(False, False, False), (False, False, False),
12701270
(False, False, False)],
1271-
fill_value=(b'N/A', 1.e+20, 1.e+20),
1271+
fill_value=(b'N/A', 1e+20, 1e+20),
12721272
dtype=[('A', 'S3'), ('B', '<f8'), ('C', '<f8')])
12731273
12741274
"""

numpy/ma/core.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ def masked_where(condition, a, copy=True):
18781878
>>> ma.masked_where(a == 2, b)
18791879
masked_array(data=['a', 'b', --, 'd'],
18801880
mask=[False, False, True, False],
1881-
fill_value='N/A',
1881+
fill_value=np.str_('N/A'),
18821882
dtype='<U1')
18831883
18841884
Effect of the `copy` argument.
@@ -3715,23 +3715,23 @@ def fill_value(self):
37153715
>>> for dt in [np.int32, np.int64, np.float64, np.complex128]:
37163716
... np.ma.array([0, 1], dtype=dt).get_fill_value()
37173717
...
3718-
999999
3719-
999999
3720-
1e+20
3721-
(1e+20+0j)
3718+
np.int64(999999)
3719+
np.int64(999999)
3720+
np.float64(1e+20)
3721+
np.complex128(1e+20+0j)
37223722
37233723
>>> x = np.ma.array([0, 1.], fill_value=-np.inf)
37243724
>>> x.fill_value
3725-
-inf
3725+
np.float64(-inf)
37263726
>>> x.fill_value = np.pi
37273727
>>> x.fill_value
3728-
3.1415926535897931 # may vary
3728+
np.float64(3.1415926535897931)
37293729
37303730
Reset to default:
37313731
37323732
>>> x.fill_value = None
37333733
>>> x.fill_value
3734-
1e+20
3734+
np.float64(1e+20)
37353735
37363736
"""
37373737
if self._fill_value is None:
@@ -4061,7 +4061,7 @@ def __repr__(self):
40614061
# The dtype of the fill value should match that of the array
40624062
# and it is unnecessary to print the full `np.int64(...)`
40634063
fill_repr = np.core.arrayprint.get_formatter(
4064-
dtype=self.fill_value.dtype, fmt=repr)(self.fill_value)
4064+
dtype=self._fill_value.dtype, fmt=repr)(self.fill_value)
40654065
else:
40664066
# Fall back to the normal repr just in case something is weird:
40674067
fill_repr = repr(self.fill_value)
@@ -6009,7 +6009,7 @@ def ptp(self, axis=None, out=None, fill_value=None, keepdims=False):
60096009
>>> y.ptp(axis=1)
60106010
masked_array(data=[ 126, 127, -128, -127],
60116011
mask=False,
6012-
fill_value=999999,
6012+
fill_value=np.int64(999999),
60136013
dtype=int8)
60146014
60156015
A work-around is to use the `view()` method to view the result as
@@ -6018,7 +6018,7 @@ def ptp(self, axis=None, out=None, fill_value=None, keepdims=False):
60186018
>>> y.ptp(axis=1).view(np.uint8)
60196019
masked_array(data=[126, 127, 128, 129],
60206020
mask=False,
6021-
fill_value=999999,
6021+
fill_value=np.int64(999999),
60226022
dtype=uint8)
60236023
"""
60246024
if out is None:
@@ -8173,7 +8173,7 @@ def fromflex(fxarray):
81738173
[0, 0]],
81748174
mask=[[False, False],
81758175
[False, False]],
8176-
fill_value=999999,
8176+
fill_value=np.int64(999999),
81778177
dtype=int32)
81788178
81798179
"""

numpy/ma/extras.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def masked_all_like(arr):
192192
[--, --, --]],
193193
mask=[[ True, True, Tru 1241 e],
194194
[ True, True, True]],
195-
fill_value=1e+20,
195+
fill_value=np.float64(1e+20),
196< 461B /code>196
dtype=float32)
197197
198198
The dtype of the masked array matches the dtype of `arr`.

0 commit comments

Comments
 (0)
0