diff options
author | mattip <matti.picus@gmail.com> | 2018-04-17 13:46:36 +0300 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2018-04-17 16:54:10 +0300 |
commit | df8e83538461c29bc12c44198574bde8ffefcad7 (patch) | |
tree | d16f3b97dfa068fce3f081bdcd6a7c94240bb426 /numpy | |
parent | 8323be1bc44c2811fc36f5b99c1a30ebcee8edbd (diff) | |
download | numpy-df8e83538461c29bc12c44198574bde8ffefcad7.tar.gz |
DOC: clear up warnings, fix matplotlib plot
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/add_newdocs.py | 18 | ||||
-rw-r--r-- | numpy/core/arrayprint.py | 164 | ||||
-rw-r--r-- | numpy/core/code_generators/ufunc_docstrings.py | 4 | ||||
-rw-r--r-- | numpy/core/src/multiarray/scalartypes.c.src | 3 | ||||
-rw-r--r-- | numpy/doc/constants.py | 3 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 29 | ||||
-rw-r--r-- | numpy/lib/mixins.py | 4 | ||||
-rw-r--r-- | numpy/lib/nanfunctions.py | 15 | ||||
-rw-r--r-- | numpy/lib/npyio.py | 15 |
9 files changed, 131 insertions, 124 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index c2348b462..bbbc34759 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -6153,10 +6153,10 @@ add_newdoc('numpy.core', 'ufunc', ('at', Performs unbuffered in place operation on operand 'a' for elements specified by 'indices'. For addition ufunc, this method is equivalent to - `a[indices] += b`, except that results are accumulated for elements that - are indexed more than once. For example, `a[[0,0]] += 1` will only + ``a[indices] += b``, except that results are accumulated for elements that + are indexed more than once. For example, ``a[[0,0]] += 1`` will only increment the first element once because of buffering, whereas - `add.at(a, [0,0], 1)` will increment the first element twice. + ``add.at(a, [0,0], 1)`` will increment the first element twice. .. versionadded:: 1.8.0 @@ -6181,8 +6181,6 @@ add_newdoc('numpy.core', 'ufunc', ('at', >>> print(a) array([-1, -2, 3, 4]) - :: - Increment items 0 and 1, and increment item 2 twice: >>> a = np.array([1, 2, 3, 4]) @@ -6190,8 +6188,6 @@ add_newdoc('numpy.core', 'ufunc', ('at', >>> print(a) array([2, 3, 5, 4]) - :: - Add items 0 and 1 in first array to second array, and store results in first array: @@ -6978,7 +6974,7 @@ add_newdoc('numpy.core.multiarray', 'datetime_as_string', arr : array_like of datetime64 The array of UTC timestamps to format. unit : str - One of None, 'auto', or a datetime unit. + One of None, 'auto', or a :ref:`datetime unit <arrays.dtypes.dateunits>`. timezone : {'naive', 'UTC', 'local'} or tzinfo Timezone information to use when displaying the datetime. If 'UTC', end with a Z to indicate UTC time. If 'local', convert to the local timezone @@ -7006,13 +7002,13 @@ add_newdoc('numpy.core.multiarray', 'datetime_as_string', '2002-10-27T07:30Z'], dtype='<U35') Note that we picked datetimes that cross a DST boundary. Passing in a - ``pytz`` timezone object will print the appropriate offset:: + ``pytz`` timezone object will print the appropriate offset >>> np.datetime_as_string(d, timezone=pytz.timezone('US/Eastern')) array(['2002-10-27T00:30-0400', '2002-10-27T01:30-0400', '2002-10-27T01:30-0500', '2002-10-27T02:30-0500'], dtype='<U39') - Passing in a unit will change the precision:: + Passing in a unit will change the precision >>> np.datetime_as_string(d, unit='h') array(['2002-10-27T04', '2002-10-27T05', '2002-10-27T06', '2002-10-27T07'], @@ -7021,7 +7017,7 @@ add_newdoc('numpy.core.multiarray', 'datetime_as_string', array(['2002-10-27T04:30:00', '2002-10-27T05:30:00', '2002-10-27T06:30:00', '2002-10-27T07:30:00'], dtype='<U38') - But can be made to not lose precision:: + 'casting' can be used to specify whether precision can be changed >>> np.datetime_as_string(d, unit='h', casting='safe') TypeError: Cannot create a datetime string as units 'h' from a NumPy diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 7dc73d6de..ad0f630ba 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -132,44 +132,45 @@ def set_printoptions(precision=None, threshold=None, edgeitems=None, formatting function applies to. Callables should return a string. Types that are not specified (by their corresponding keys) are handled by the default formatters. Individual types for which a formatter - can be set are:: - - - 'bool' - - 'int' - - 'timedelta' : a `numpy.timedelta64` - - 'datetime' : a `numpy.datetime64` - - 'float' - - 'longfloat' : 128-bit floats - - 'complexfloat' - - 'longcomplexfloat' : composed of two 128-bit floats - - 'numpystr' : types `numpy.string_` and `numpy.unicode_` - - 'object' : `np.object_` arrays - - 'str' : all other strings - - Other keys that can be used to set a group of types at once are:: - - - 'all' : sets all types - - 'int_kind' : sets 'int' - - 'float_kind' : sets 'float' and 'longfloat' - - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat' - - 'str_kind' : sets 'str' and 'numpystr' + can be set are: + + - 'bool' + - 'int' + - 'timedelta' : a `numpy.timedelta64` + - 'datetime' : a `numpy.datetime64` + - 'float' + - 'longfloat' : 128-bit floats + - 'complexfloat' + - 'longcomplexfloat' : composed of two 128-bit floats + - 'numpystr' : types `numpy.string_` and `numpy.unicode_` + - 'object' : `np.object_` arrays + - 'str' : all other strings + + Other keys that can be used to set a group of types at once are: + + - 'all' : sets all types + - 'int_kind' : sets 'int' + - 'float_kind' : sets 'float' and 'longfloat' + - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat' + - 'str_kind' : sets 'str' and 'numpystr' floatmode : str, optional Controls the interpretation of the `precision` option for floating-point types. Can take the following values: - - 'fixed' : Always print exactly `precision` fractional digits, - even if this would print more or fewer digits than - necessary to specify the value uniquely. - - 'unique : Print the minimum number of fractional digits necessary - to represent each value uniquely. Different elements may - have a different number of digits. The value of the - `precision` option is ignored. - - 'maxprec' : Print at most `precision` fractional digits, but if - an element can be uniquely represented with fewer digits - only print it with that many. - - 'maxprec_equal' : Print at most `precision` fractional digits, - but if every element in the array can be uniquely - represented with an equal number of fewer digits, use that - many digits for all elements. + + * 'fixed': Always print exactly `precision` fractional digits, + even if this would print more or fewer digits than + necessary to specify the value uniquely. + * 'unique': Print the minimum number of fractional digits necessary + to represent each value uniquely. Different elements may + have a different number of digits. The value of the + `precision` option is ignored. + * 'maxprec': Print at most `precision` fractional digits, but if + an element can be uniquely represented with fewer digits + only print it with that many. + * 'maxprec_equal': Print at most `precision` fractional digits, + but if every element in the array can be uniquely + represented with an equal number of fewer digits, use that + many digits for all elements. legacy : string or `False`, optional If set to the string `'1.13'` enables 1.13 legacy printing mode. This approximates numpy 1.13 print output by including a space in the sign @@ -536,27 +537,27 @@ def array2string(a, max_line_width=None, precision=None, formatting function applies to. Callables should return a string. Types that are not specified (by their corresponding keys) are handled by the default formatters. Individual types for which a formatter - can be set are:: - - - 'bool' - - 'int' - - 'timedelta' : a `numpy.timedelta64` - - 'datetime' : a `numpy.datetime64` - - 'float' - - 'longfloat' : 128-bit floats - - 'complexfloat' - - 'longcomplexfloat' : composed of two 128-bit floats - - 'void' : type `numpy.void` - - 'numpystr' : types `numpy.string_` and `numpy.unicode_` - - 'str' : all other strings - - Other keys that can be used to set a group of types at once are:: - - - 'all' : sets all types - - 'int_kind' : sets 'int' - - 'float_kind' : sets 'float' and 'longfloat' - - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat' - - 'str_kind' : sets 'str' and 'numpystr' + can be set are: + + - 'bool' + - 'int' + - 'timedelta' : a `numpy.timedelta64` + - 'datetime' : a `numpy.datetime64` + - 'float' + - 'longfloat' : 128-bit floats + - 'complexfloat' + - 'longcomplexfloat' : composed of two 128-bit floats + - 'void' : type `numpy.void` + - 'numpystr' : types `numpy.string_` and `numpy.unicode_` + - 'str' : all other strings + + Other keys that can be used to set a group of types at once are: + + - 'all' : sets all types + - 'int_kind' : sets 'int' + - 'float_kind' : sets 'float' and 'longfloat' + - 'complex_kind' : sets 'complexfloat' and 'longcomplexfloat' + - 'str_kind' : sets 'str' and 'numpystr' threshold : int, optional Total number of array elements which trigger summarization rather than full repr. @@ -571,20 +572,21 @@ def array2string(a, max_line_width=None, precision=None, floatmode : str, optional Controls the interpretation of the `precision` option for floating-point types. Can take the following values: - - 'fixed' : Always print exactly `precision` fractional digits, - even if this would print more or fewer digits than - necessary to specify the value uniquely. - - 'unique : Print the minimum number of fractional digits necessary - to represent each value uniquely. Different elements may - have a different number of digits. The value of the - `precision` option is ignored. - - 'maxprec' : Print at most `precision` fractional digits, but if - an element can be uniquely represented with fewer digits - only print it with that many. - - 'maxprec_equal' : Print at most `precision` fractional digits, - but if every element in the array can be uniquely - represented with an equal number of fewer digits, use that - many digits for all elements. + + - 'fixed': Always print exactly `precision` fractional digits, + even if this would print more or fewer digits than + necessary to specify the value uniquely. + - 'unique': Print the minimum number of fractional digits necessary + to represent each value uniquely. Different elements may + have a different number of digits. The value of the + `precision` option is ignored. + - 'maxprec': Print at most `precision` fractional digits, but if + an element can be uniquely represented with fewer digits + only print it with that many. + - 'maxprec_equal': Print at most `precision` fractional digits, + but if every element in the array can be uniquely + represented with an equal number of fewer digits, use that + many digits for all elements. legacy : string or `False`, optional If set to the string `'1.13'` enables 1.13 legacy printing mode. This approximates numpy 1.13 print output by including a space in the sign @@ -984,11 +986,12 @@ def format_float_scientific(x, precision=None, unique=True, trim='k', value. trim : one of 'k', '.', '0', '-', optional Controls post-processing trimming of trailing digits, as follows: - k : keep trailing zeros, keep decimal point (no trimming) - . : trim all trailing zeros, leave decimal point - 0 : trim all but the zero before the decimal point. Insert the - zero if it is missing. - - : trim trailing zeros and any trailing decimal point + + * 'k' : keep trailing zeros, keep decimal point (no trimming) + * '.' : trim all trailing zeros, leave decimal point + * '0' : trim all but the zero before the decimal point. Insert the + zero if it is missing. + * '-' : trim trailing zeros and any trailing decimal point sign : boolean, optional Whether to show the sign for positive values. pad_left : non-negative integer, optional @@ -1056,11 +1059,12 @@ def format_float_positional(x, precision=None, unique=True, digits, before or after the decimal point, ignoring leading zeros. trim : one of 'k', '.', '0', '-', optional Controls post-processing trimming of trailing digits, as follows: - k : keep trailing zeros, keep decimal point (no trimming) - . : trim all trailing zeros, leave decimal point - 0 : trim all but the zero before the decimal point. Insert the - zero if it is missing. - - : trim trailing zeros and any trailing decimal point + + 'k' : keep trailing zeros, keep decimal point (no trimming) + '.' : trim all trailing zeros, leave decimal point + '0' : trim all but the zero before the decimal point. Insert the + zero if it is missing. + '-' : trim trailing zeros and any trailing decimal point sign : boolean, optional Whether to show the sign for positive values. pad_left : non-negative integer, optional diff --git a/numpy/core/code_generators/ufunc_docstrings.py b/numpy/core/code_generators/ufunc_docstrings.py index 615970816..c51b3cae1 100644 --- a/numpy/core/code_generators/ufunc_docstrings.py +++ b/numpy/core/code_generators/ufunc_docstrings.py @@ -3744,7 +3744,7 @@ add_newdoc('numpy.core.umath', 'ldexp', add_newdoc('numpy.core.umath', 'gcd', """ - Returns the greatest common divisor of |x1| and |x2| + Returns the greatest common divisor of x1 and x2 Parameters ---------- @@ -3774,7 +3774,7 @@ add_newdoc('numpy.core.umath', 'gcd', add_newdoc('numpy.core.umath', 'lcm', """ - Returns the lowest common multiple of |x1| and |x2| + Returns the lowest common multiple of x1 and x2 Parameters ---------- diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src index 9df635dee..cb4af0d12 100644 --- a/numpy/core/src/multiarray/scalartypes.c.src +++ b/numpy/core/src/multiarray/scalartypes.c.src @@ -1607,7 +1607,8 @@ static PyGetSetDef gentype_getsets[] = { /* 0-dim array from scalar object */ -static char doc_getarray[] = "sc.__array__(|type) return 0-dim array"; +static char doc_getarray[] = "sc.__array__(dtype) return 0-dim array from " + "scalar with specified dtype"; static PyObject * gentype_getarray(PyObject *scalar, PyObject *args) diff --git a/numpy/doc/constants.py b/numpy/doc/constants.py index f3b835085..21c7a3c67 100644 --- a/numpy/doc/constants.py +++ b/numpy/doc/constants.py @@ -296,8 +296,9 @@ add_newdoc('numpy', 'nan', See Also -------- isnan : Shows which elements are Not a Number. + isfinite : Shows which elements are finite (not one of - Not a Number, positive infinity and negative infinity) + Not a Number, positive infinity and negative infinity) Notes ----- diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 8440be52e..0e517ee8f 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3400,17 +3400,19 @@ def percentile(a, q, axis=None, out=None, If True, then allow the input array `a` to be modified by intermediate calculations, to save memory. In this case, the contents of the input `a` after this function completes is undefined. + interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'} This optional parameter specifies the interpolation method to use when the desired quantile lies between two data points ``i < j``: - * linear: ``i + (j - i) * fraction``, where ``fraction`` - is the fractional part of the index surrounded by ``i`` - and ``j``. - * lower: ``i``. - * higher: ``j``. - * nearest: ``i`` or ``j``, whichever is nearest. - * midpoint: ``(i + j) / 2``. + + * 'linear': ``i + (j - i) * fraction``, where ``fraction`` + is the fractional part of the index surrounded by ``i`` + and ``j``. + * 'lower': ``i``. + * 'higher': ``j``. + * 'nearest': ``i`` or ``j``, whichever is nearest. + * 'midpoint': ``(i + j) / 2``. .. versionadded:: 1.9.0 keepdims : bool, optional @@ -3479,18 +3481,19 @@ def percentile(a, q, axis=None, out=None, The different types of interpolation can be visualized graphically: - ..plot:: + .. plot:: + import matplotlib.pyplot as plt a = np.arange(4) p = np.linspace(0, 100, 6001) ax = plt.gca() lines = [ - ('linear', None) - ('higher', '--') - ('lower', '--') - ('nearest', '-.') - ('midpoint', '-.') + ('linear', None), + ('higher', '--'), + ('lower', '--'), + ('nearest', '-.'), + ('midpoint', '-.'), ] for interpolation, style in lines: ax.plot( diff --git a/numpy/lib/mixins.py b/numpy/lib/mixins.py index 3220f6534..0379ecb1a 100644 --- a/numpy/lib/mixins.py +++ b/numpy/lib/mixins.py @@ -74,8 +74,8 @@ class NDArrayOperatorsMixin(object): It is useful for writing classes that do not inherit from `numpy.ndarray`, but that should support arithmetic and numpy universal functions like - arrays as described in :ref:`A Mechanism for Overriding Ufuncs - <neps.ufunc-overrides>`. + arrays as described in `A Mechanism for Overriding Ufuncs + <../../neps/nep-0013-ufunc-overrides.html>`_. As an trivial example, consider this implementation of an ``ArrayLike`` class that simply wraps a NumPy array and ensures that the result of any diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py index 16e363d7c..dddc0e5b8 100644 --- a/numpy/lib/nanfunctions.py +++ b/numpy/lib/nanfunctions.py @@ -1059,13 +1059,14 @@ def nanpercentile(a, q, axis=None, out=None, overwrite_input=False, This optional parameter specifies the interpolation method to use when the desired quantile lies between two data points ``i < j``: - * linear: ``i + (j - i) * fraction``, where ``fraction`` - is the fractional part of the index surrounded by ``i`` - and ``j``. - * lower: ``i``. - * higher: ``j``. - * nearest: ``i`` or ``j``, whichever is nearest. - * midpoint: ``(i + j) / 2``. + + * 'linear': ``i + (j - i) * fraction``, where ``fraction`` + is the fractional part of the index surrounded by ``i`` + and ``j``. + * 'lower': ``i``. + * 'higher': ``j``. + * 'nearest': ``i`` or ``j``, whichever is nearest. + * 'midpoint': ``(i + j) / 2``. keepdims : bool, optional If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 29688f73d..59379bdda 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1166,13 +1166,14 @@ def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', multi-format string, e.g. 'Iteration %d -- %10.5f', in which case `delimiter` is ignored. For complex `X`, the legal options for `fmt` are: - a) a single specifier, `fmt='%.4e'`, resulting in numbers formatted - like `' (%s+%sj)' % (fmt, fmt)` - b) a full string specifying every real and imaginary part, e.g. - `' %.4e %+.4ej %.4e %+.4ej %.4e %+.4ej'` for 3 columns - c) a list of specifiers, one per column - in this case, the real - and imaginary part must have separate specifiers, - e.g. `['%.3e + %.3ej', '(%.15e%+.15ej)']` for 2 columns + + * a single specifier, `fmt='%.4e'`, resulting in numbers formatted + like `' (%s+%sj)' % (fmt, fmt)` + * a full string specifying every real and imaginary part, e.g. + `' %.4e %+.4ej %.4e %+.4ej %.4e %+.4ej'` for 3 columns + * a list of specifiers, one per column - in this case, the real + and imaginary part must have separate specifiers, + e.g. `['%.3e + %.3ej', '(%.15e%+.15ej)']` for 2 columns delimiter : str, optional String or character separating columns. newline : str, optional |