Skip to content
Snippets Groups Projects
Commit 4a740ccf authored by Sandro Tosi's avatar Sandro Tosi
Browse files

New upstream version 1.16.5

parent f5956cfa
No related branches found
No related tags found
No related merge requests found
Showing
with 581 additions and 46 deletions
......@@ -11,15 +11,18 @@ include site.cfg.example
include numpy/random/mtrand/generate_mtrand_c.py
recursive-include numpy/random/mtrand *.pyx *.pxd
# Add build support that should go in sdist, but not go in bdist/be installed
# Note that sub-directories that don't have __init__ are apparently not
# included by 'recursive-include', so list those separately
recursive-include numpy *
recursive-include numpy/_build_utils *
recursive-include numpy/linalg/lapack_lite *.c *.h
recursive-include numpy/linalg/lapack_lite *
include runtests.py
include tox.ini pytest.ini .coveragerc
recursive-include tools *
# Add sdist files whose use depends on local configuration.
include numpy/core/src/common/cblasfuncs.c
include numpy/core/src/common/python_xerbla.c
# Adding scons build related files not found by distutils
# Adding build related files not found by distutils
recursive-include numpy/core/code_generators *.py *.txt
recursive-include numpy/core *.in *.h
# Add documentation and benchmarks: we don't use add_data_dir since we do not
......
Metadata-Version: 1.2
Name: numpy
Version: 1.16.2
Version: 1.16.5
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: NumPy Developers
Author-email: numpy-discussion@python.org
License: BSD
Download-URL: https://pypi.python.org/pypi/numpy
Project-URL: Bug Tracker, https://github.com/numpy/numpy/issues
Project-URL: Source Code, https://github.com/numpy/numpy
Description-Content-Type: UNKNOWN
Description: It provides:
......
Contributors
============
A total of 16 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
* Andreas Schwab
* Bharat Raghunathan +
* Bran +
* Charles Harris
* Eric Wieser
* Jakub Wilk
* Kevin Sheppard
* Marten van Kerkwijk
* Matti Picus
* Paul Ivanov
* Ralf Gommers
* Sebastian Berg
* Tyler Reddy
* Warren Weckesser
* Yu Feng
* adeak +
Pull requests merged
====================
A total of 26 pull requests were merged for this release.
* `#13072 <https://github.com/numpy/numpy/pull/13072>`__: BUG: Fixes to numpy.distutils.Configuration.get_version (#13056)
* `#13082 <https://github.com/numpy/numpy/pull/13082>`__: BUG: Fix errors in string formatting while producing an error
* `#13083 <https://github.com/numpy/numpy/pull/13083>`__: BUG: Convert fortran flags in environment variable
* `#13084 <https://github.com/numpy/numpy/pull/13084>`__: BUG: Remove error-prone borrowed reference handling
* `#13085 <https://github.com/numpy/numpy/pull/13085>`__: BUG: Add error checks when converting integers to datetime types
* `#13091 <https://github.com/numpy/numpy/pull/13091>`__: BUG: Remove our patched version of `distutils.split_quoted`
* `#13141 <https://github.com/numpy/numpy/pull/13141>`__: BUG: Fix testsuite failures on ppc and riscv
* `#13142 <https://github.com/numpy/numpy/pull/13142>`__: BUG: Fix parameter validity checks in ``random.choice``
* `#13143 <https://github.com/numpy/numpy/pull/13143>`__: BUG: Ensure linspace works on object input.
* `#13144 <https://github.com/numpy/numpy/pull/13144>`__: BLD: fix include list for sdist building.
* `#13145 <https://github.com/numpy/numpy/pull/13145>`__: BUG: __array_interface__ offset was always ignored
* `#13274 <https://github.com/numpy/numpy/pull/13274>`__: MAINT: f2py: Add a cast to avoid a compiler warning.
* `#13275 <https://github.com/numpy/numpy/pull/13275>`__: BUG, MAINT: fix reference count error on invalid input to ndarray.flat
* `#13276 <https://github.com/numpy/numpy/pull/13276>`__: ENH: Cast covariance to double in random mvnormal
* `#13278 <https://github.com/numpy/numpy/pull/13278>`__: BUG: Fix null pointer dereference in PyArray_DTypeFromObjectHelper
* `#13339 <https://github.com/numpy/numpy/pull/13339>`__: BUG: Use C call to sysctlbyname for AVX detection on MacOS.
* `#13340 <https://github.com/numpy/numpy/pull/13340>`__: BUG: Fix crash when calling savetxt on a padded array
* `#13341 <https://github.com/numpy/numpy/pull/13341>`__: BUG: ufunc.at iteration variable size fix
* `#13342 <https://github.com/numpy/numpy/pull/13342>`__: DOC: Add as_ctypes_type to the documentation
* `#13350 <https://github.com/numpy/numpy/pull/13350>`__: BUG: Return the coefficients array directly
* `#13351 <https://github.com/numpy/numpy/pull/13351>`__: BUG/MAINT: Tidy typeinfo.h and .c
* `#13359 <https://github.com/numpy/numpy/pull/13359>`__: BUG: Make allow_pickle=False the default for loading
* `#13360 <https://github.com/numpy/numpy/pull/13360>`__: DOC: fix some doctest failures
* `#13363 <https://github.com/numpy/numpy/pull/13363>`__: BUG/MAINT: Tidy typeinfo.h and .c
* `#13381 <https://github.com/numpy/numpy/pull/13381>`__: BLD: address mingw-w64 issue. Follow-up to gh-9977
* `#13382 <https://github.com/numpy/numpy/pull/13382>`__: REL: Prepare for the NumPy release.
Contributors
============
A total of 10 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
* Charles Harris
* Eric Wieser
* Dennis Zollo +
* Hunter Damron +
* Jingbei Li +
* Kevin Sheppard
* Matti Picus
* Nicola Soranzo +
* Sebastian Berg
* Tyler Reddy
Pull requests merged
====================
A total of 16 pull requests were merged for this release.
* `#13392 <https://github.com/numpy/numpy/pull/13392>`__: BUG: Some PyPy versions lack PyStructSequence_InitType2.
* `#13394 <https://github.com/numpy/numpy/pull/13394>`__: MAINT, DEP: Fix deprecated ``assertEquals()``
* `#13396 <https://github.com/numpy/numpy/pull/13396>`__: BUG: Fix structured_to_unstructured on single-field types (backport)
* `#13549 <https://github.com/numpy/numpy/pull/13549>`__: BLD: Make CI pass again with pytest 4.5
* `#13552 <https://github.com/numpy/numpy/pull/13552>`__: TST: Register markers in conftest.py.
* `#13559 <https://github.com/numpy/numpy/pull/13559>`__: BUG: Removes ValueError for empty kwargs in arraymultiter_new
* `#13560 <https://github.com/numpy/numpy/pull/13560>`__: BUG: Add TypeError to accepted exceptions in crackfortran.
* `#13561 <https://github.com/numpy/numpy/pull/13561>`__: BUG: Handle subarrays in descr_to_dtype
* `#13562 <https://github.com/numpy/numpy/pull/13562>`__: BUG: Protect generators from log(0.0)
* `#13563 <https://github.com/numpy/numpy/pull/13563>`__: BUG: Always return views from structured_to_unstructured when...
* `#13564 <https://github.com/numpy/numpy/pull/13564>`__: BUG: Catch stderr when checking compiler version
* `#13565 <https://github.com/numpy/numpy/pull/13565>`__: BUG: longdouble(int) does not work
* `#13587 <https://github.com/numpy/numpy/pull/13587>`__: BUG: distutils/system_info.py fix missing subprocess import (#13523)
* `#13620 <https://github.com/numpy/numpy/pull/13620>`__: BUG,DEP: Fix writeable flag setting for arrays without base
* `#13641 <https://github.com/numpy/numpy/pull/13641>`__: MAINT: Prepare for the 1.16.4 release.
* `#13644 <https://github.com/numpy/numpy/pull/13644>`__: BUG: special case object arrays when printing rel-, abs-error
Contributors
============
A total of 18 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
* Alexander Shadchin
* Allan Haldane
* Bruce Merry +
* Charles Harris
* Colin Snyder +
* Dan Allan +
* Emile +
* Eric Wieser
* Grey Baker +
* Maksim Shabunin +
* Marten van Kerkwijk
* Matti Picus
* Peter Andreas Entschev +
* Ralf Gommers
* Richard Harris +
* Sebastian Berg
* Sergei Lebedev +
* Stephan Hoyer
Pull requests merged
====================
A total of 23 pull requests were merged for this release.
* `#13742 <https://github.com/numpy/numpy/pull/13742>`__: ENH: Add project URLs to setup.py
* `#13823 <https://github.com/numpy/numpy/pull/13823>`__: TEST, ENH: fix tests and ctypes code for PyPy
* `#13845 <https://github.com/numpy/numpy/pull/13845>`__: BUG: use npy_intp instead of int for indexing array
* `#13867 <https://github.com/numpy/numpy/pull/13867>`__: TST: Ignore DeprecationWarning during nose imports
* `#13905 <https://github.com/numpy/numpy/pull/13905>`__: BUG: Fix use-after-free in boolean indexing
* `#13933 <https://github.com/numpy/numpy/pull/13933>`__: MAINT/BUG/DOC: Fix errors in _add_newdocs
* `#13984 <https://github.com/numpy/numpy/pull/13984>`__: BUG: fix byte order reversal for datetime64[ns]
* `#13994 <https://github.com/numpy/numpy/pull/13994>`__: MAINT,BUG: Use nbytes to also catch empty descr during allocation
* `#14042 <https://github.com/numpy/numpy/pull/14042>`__: BUG: np.array cleared errors occured in PyMemoryView_FromObject
* `#14043 <https://github.com/numpy/numpy/pull/14043>`__: BUG: Fixes for Undefined Behavior Sanitizer (UBSan) errors.
* `#14044 <https://github.com/numpy/numpy/pull/14044>`__: BUG: ensure that casting to/from structured is properly checked.
* `#14045 <https://github.com/numpy/numpy/pull/14045>`__: MAINT: fix histogram*d dispatchers
* `#14046 <https://github.com/numpy/numpy/pull/14046>`__: BUG: further fixup to histogram2d dispatcher.
* `#14052 <https://github.com/numpy/numpy/pull/14052>`__: BUG: Replace contextlib.suppress for Python 2.7
* `#14056 <https://github.com/numpy/numpy/pull/14056>`__: BUG: fix compilation of 3rd party modules with Py_LIMITED_API...
* `#14057 <https://github.com/numpy/numpy/pull/14057>`__: BUG: Fix memory leak in dtype from dict contructor
* `#14058 <https://github.com/numpy/numpy/pull/14058>`__: DOC: Document array_function at a higher level.
* `#14084 <https://github.com/numpy/numpy/pull/14084>`__: BUG, DOC: add new recfunctions to `__all__`
* `#14162 <https://github.com/numpy/numpy/pull/14162>`__: BUG: Remove stray print that causes a SystemError on python 3.7
* `#14297 <https://github.com/numpy/numpy/pull/14297>`__: TST: Pin pytest version to 5.0.1.
* `#14322 <https://github.com/numpy/numpy/pull/14322>`__: ENH: Enable huge pages in all Linux builds
* `#14346 <https://github.com/numpy/numpy/pull/14346>`__: BUG: fix behavior of structured_to_unstructured on non-trivial...
* `#14382 <https://github.com/numpy/numpy/pull/14382>`__: REL: Prepare for the NumPy 1.16.5 release.
......@@ -80,9 +80,9 @@ Improvements
Further improvements to ``ctypes`` support in ``np.ctypeslib``
--------------------------------------------------------------
A new ``np.ctypeslib.as_ctypes_type`` function has been added, which can be
A new `numpy.ctypeslib.as_ctypes_type` function has been added, which can be
used to converts a `dtype` into a best-guess `ctypes` type. Thanks to this
new function, ``np.ctypeslib.as_ctypes`` now supports a much wider range of
new function, `numpy.ctypeslib.as_ctypes` now supports a much wider range of
array types, including structures, booleans, and integers of non-native
endianness.
......
==========================
NumPy 1.16.3 Release Notes
==========================
The NumPy 1.16.3 release fixes bugs reported against the 1.16.2 release, and
also backports several enhancements from master that seem appropriate for a
release series that is the last to support Python 2.7. The wheels on PyPI are
linked with OpenBLAS v0.3.4+, which should fix the known threading issues
found in previous OpenBLAS versions.
Downstream developers building this release should use Cython >= 0.29.2 and,
if using OpenBLAS, OpenBLAS > v0.3.4.
The most noticeable change in this release is that unpickling object arrays
when loading ``*.npy`` or ``*.npz`` files now requires an explicit opt-in.
This backwards incompatible change was made in response to
`CVE-2019-6446 <https://nvd.nist.gov/vuln/detail/CVE-2019-6446>`_.
Compatibility notes
===================
Unpickling while loading requires explicit opt-in
-------------------------------------------------
The functions ``np.load``, and ``np.lib.format.read_array`` take an
`allow_pickle` keyword which now defaults to ``False`` in response to
`CVE-2019-6446 <https://nvd.nist.gov/vuln/detail/CVE-2019-6446>`_.
Improvements
============
Covariance in `random.mvnormal` cast to double
----------------------------------------------
This should make the tolerance used when checking the singular values of the
covariance matrix more meaningful.
Changes
=======
``__array_interface__`` offset now works as documented
------------------------------------------------------
The interface may use an ``offset`` value that was previously mistakenly
ignored.
==========================
NumPy 1.16.4 Release Notes
==========================
The NumPy 1.16.4 release fixes bugs reported against the 1.16.3 release, and
also backports several enhancements from master that seem appropriate for a
release series that is the last to support Python 2.7. The wheels on PyPI are
linked with OpenBLAS v0.3.7-dev, which should fix issues on Skylake series
cpus.
Downstream developers building this release should use Cython >= 0.29.2 and,
if using OpenBLAS, OpenBLAS > v0.3.7. The supported Python versions are 2.7 and
3.5-3.7.
New deprecations
================
Writeable flag of C-API wrapped arrays
--------------------------------------
When an array is created from the C-API to wrap a pointer to data, the only
indication we have of the read-write nature of the data is the ``writeable``
flag set during creation. It is dangerous to force the flag to writeable. In
the future it will not be possible to switch the writeable flag to ``True``
from python. This deprecation should not affect many users since arrays
created in such a manner are very rare in practice and only available through
the NumPy C-API.
Compatibility notes
===================
Potential changes to the random stream
--------------------------------------
Due to bugs in the application of log to random floating point numbers,
the stream may change when sampling from ``np.random.beta``, ``np.random.binomial``,
``np.random.laplace``, ``np.random.logistic``, ``np.random.logseries`` or
``np.random.multinomial`` if a 0 is generated in the underlying MT19937 random stream.
There is a 1 in :math:`10^{53}` chance of this occurring, and so the probability that
the stream changes for any given seed is extremely small. If a 0 is encountered in the
underlying generator, then the incorrect value produced (either ``np.inf``
or ``np.nan``) is now dropped.
Changes
=======
`numpy.lib.recfunctions.structured_to_unstructured` does not squeeze single-field views
---------------------------------------------------------------------------------------
Previously ``structured_to_unstructured(arr[['a']])`` would produce a squeezed
result inconsistent with ``structured_to_unstructured(arr[['a', b']])``. This
was accidental. The old behavior can be retained with
``structured_to_unstructured(arr[['a']]).squeeze(axis=-1)`` or far more simply,
``arr['a']``.
Contributors
============
A total of 10 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
* Charles Harris
* Eric Wieser
* Dennis Zollo +
* Hunter Damron +
* Jingbei Li +
* Kevin Sheppard
* Matti Picus
* Nicola Soranzo +
* Sebastian Berg
* Tyler Reddy
Pull requests merged
====================
A total of 16 pull requests were merged for this release.
* `#13392 <https://github.com/numpy/numpy/pull/13392>`__: BUG: Some PyPy versions lack PyStructSequence_InitType2.
* `#13394 <https://github.com/numpy/numpy/pull/13394>`__: MAINT, DEP: Fix deprecated ``assertEquals()``
* `#13396 <https://github.com/numpy/numpy/pull/13396>`__: BUG: Fix structured_to_unstructured on single-field types (backport)
* `#13549 <https://github.com/numpy/numpy/pull/13549>`__: BLD: Make CI pass again with pytest 4.5
* `#13552 <https://github.com/numpy/numpy/pull/13552>`__: TST: Register markers in conftest.py.
* `#13559 <https://github.com/numpy/numpy/pull/13559>`__: BUG: Removes ValueError for empty kwargs in arraymultiter_new
* `#13560 <https://github.com/numpy/numpy/pull/13560>`__: BUG: Add TypeError to accepted exceptions in crackfortran.
* `#13561 <https://github.com/numpy/numpy/pull/13561>`__: BUG: Handle subarrays in descr_to_dtype
* `#13562 <https://github.com/numpy/numpy/pull/13562>`__: BUG: Protect generators from log(0.0)
* `#13563 <https://github.com/numpy/numpy/pull/13563>`__: BUG: Always return views from structured_to_unstructured when...
* `#13564 <https://github.com/numpy/numpy/pull/13564>`__: BUG: Catch stderr when checking compiler version
* `#13565 <https://github.com/numpy/numpy/pull/13565>`__: BUG: longdouble(int) does not work
* `#13587 <https://github.com/numpy/numpy/pull/13587>`__: BUG: distutils/system_info.py fix missing subprocess import (#13523)
* `#13620 <https://github.com/numpy/numpy/pull/13620>`__: BUG,DEP: Fix writeable flag setting for arrays without base
* `#13641 <https://github.com/numpy/numpy/pull/13641>`__: MAINT: Prepare for the 1.16.4 release.
* `#13644 <https://github.com/numpy/numpy/pull/13644>`__: BUG: special case object arrays when printing rel-, abs-error
==========================
NumPy 1.16.5 Release Notes
==========================
The NumPy 1.16.5 release fixes bugs reported against the 1.16.4 release, and
also backports several enhancements from master that seem appropriate for a
release series that is the last to support Python 2.7. The wheels on PyPI are
linked with OpenBLAS v0.3.7-dev, which should fix errors on Skylake series
cpus.
Downstream developers building this release should use Cython >= 0.29.2 and, if
using OpenBLAS, OpenBLAS >= v0.3.7. The supported Python versions are 2.7 and
3.5-3.7.
Contributors
============
A total of 18 people contributed to this release. People with a "+" by their
names contributed a patch for the first time.
* Alexander Shadchin
* Allan Haldane
* Bruce Merry +
* Charles Harris
* Colin Snyder +
* Dan Allan +
* Emile +
* Eric Wieser
* Grey Baker +
* Maksim Shabunin +
* Marten van Kerkwijk
* Matti Picus
* Peter Andreas Entschev +
* Ralf Gommers
* Richard Harris +
* Sebastian Berg
* Sergei Lebedev +
* Stephan Hoyer
Pull requests merged
====================
A total of 23 pull requests were merged for this release.
* `#13742 <https://github.com/numpy/numpy/pull/13742>`__: ENH: Add project URLs to setup.py
* `#13823 <https://github.com/numpy/numpy/pull/13823>`__: TEST, ENH: fix tests and ctypes code for PyPy
* `#13845 <https://github.com/numpy/numpy/pull/13845>`__: BUG: use npy_intp instead of int for indexing array
* `#13867 <https://github.com/numpy/numpy/pull/13867>`__: TST: Ignore DeprecationWarning during nose imports
* `#13905 <https://github.com/numpy/numpy/pull/13905>`__: BUG: Fix use-after-free in boolean indexing
* `#13933 <https://github.com/numpy/numpy/pull/13933>`__: MAINT/BUG/DOC: Fix errors in _add_newdocs
* `#13984 <https://github.com/numpy/numpy/pull/13984>`__: BUG: fix byte order reversal for datetime64[ns]
* `#13994 <https://github.com/numpy/numpy/pull/13994>`__: MAINT,BUG: Use nbytes to also catch empty descr during allocation
* `#14042 <https://github.com/numpy/numpy/pull/14042>`__: BUG: np.array cleared errors occured in PyMemoryView_FromObject
* `#14043 <https://github.com/numpy/numpy/pull/14043>`__: BUG: Fixes for Undefined Behavior Sanitizer (UBSan) errors.
* `#14044 <https://github.com/numpy/numpy/pull/14044>`__: BUG: ensure that casting to/from structured is properly checked.
* `#14045 <https://github.com/numpy/numpy/pull/14045>`__: MAINT: fix histogram*d dispatchers
* `#14046 <https://github.com/numpy/numpy/pull/14046>`__: BUG: further fixup to histogram2d dispatcher.
* `#14052 <https://github.com/numpy/numpy/pull/14052>`__: BUG: Replace contextlib.suppress for Python 2.7
* `#14056 <https://github.com/numpy/numpy/pull/14056>`__: BUG: fix compilation of 3rd party modules with Py_LIMITED_API...
* `#14057 <https://github.com/numpy/numpy/pull/14057>`__: BUG: Fix memory leak in dtype from dict contructor
* `#14058 <https://github.com/numpy/numpy/pull/14058>`__: DOC: Document array_function at a higher level.
* `#14084 <https://github.com/numpy/numpy/pull/14084>`__: BUG, DOC: add new recfunctions to `__all__`
* `#14162 <https://github.com/numpy/numpy/pull/14162>`__: BUG: Remove stray print that causes a SystemError on python 3.7
* `#14297 <https://github.com/numpy/numpy/pull/14297>`__: TST: Pin pytest version to 5.0.1.
* `#14322 <https://github.com/numpy/numpy/pull/14322>`__: ENH: Enable huge pages in all Linux builds
* `#14346 <https://github.com/numpy/numpy/pull/14346>`__: BUG: fix behavior of structured_to_unstructured on non-trivial...
* `#14382 <https://github.com/numpy/numpy/pull/14382>`__: REL: Prepare for the NumPy 1.16.5 release.
......@@ -121,7 +121,9 @@
{%- endblock %}
{{ css() }}
{%- if not embedded %}
{%- block scripts %}
{{ script() }}
{%- endblock %}
{%- if use_opensearch %}
<link rel="search" type="application/opensearchdescription+xml"
title="{% trans docstitle=docstitle|e %}Search within {{ docstitle }}{% endtrans %}"
......
......@@ -6,8 +6,15 @@ Standard array subclasses
.. currentmodule:: numpy
The :class:`ndarray` in NumPy is a "new-style" Python
built-in-type. Therefore, it can be inherited from (in Python or in C)
.. note::
Subclassing a ``numpy.ndarray`` is possible but if your goal is to create
an array with *modified* behavior, as do dask arrays for distributed
computation and cupy arrays for GPU-based computation, subclassing is
discouraged. Instead, using numpy's
:ref:`dispatch mechanism <basics.dispatch>` is recommended.
The :class:`ndarray` can be inherited from (in Python or in C)
if desired. Therefore, it can form a foundation for many useful
classes. Often whether to sub-class the array object or to simply use
the core array component as an internal part of a new class is a
......@@ -151,6 +158,121 @@ NumPy provides several hooks that classes can customize:
:func:`__array_prepare__`, :data:`__array_priority__` mechanism
described below for ufuncs (which may eventually be deprecated).
.. py:method:: class.__array_function__(func, types, args, kwargs)
.. versionadded:: 1.16
.. note::
- In NumPy 1.17, the protocol is enabled by default, but can be disabled
with ``NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=0``.
- In NumPy 1.16, you need to set the environment variable
``NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=1`` before importing NumPy to use
NumPy function overrides.
- Eventually, expect to ``__array_function__`` to always be enabled.
- ``func`` is an arbitrary callable exposed by NumPy's public API,
which was called in the form ``func(*args, **kwargs)``.
- ``types`` is a `collection <collections.abc.Collection>`_
of unique argument types from the original NumPy function call that
implement ``__array_function__``.
- The tuple ``args`` and dict ``kwargs`` are directly passed on from the
original call.
As a convenience for ``__array_function__`` implementors, ``types``
provides all argument types with an ``'__array_function__'`` attribute.
This allows implementors to quickly identify cases where they should defer
to ``__array_function__`` implementations on other arguments.
Implementations should not rely on the iteration order of ``types``.
Most implementations of ``__array_function__`` will start with two
checks:
1. Is the given function something that we know how to overload?
2. Are all arguments of a type that we know how to handle?
If these conditions hold, ``__array_function__`` should return the result
from calling its implementation for ``func(*args, **kwargs)``. Otherwise,
it should return the sentinel value ``NotImplemented``, indicating that the
function is not implemented by these types.
There are no general requirements on the return value from
``__array_function__``, although most sensible implementations should
probably return array(s) with the same type as one of the function's
arguments.
It may also be convenient to define a custom decorators (``implements``
below) for registering ``__array_function__`` implementations.
.. code:: python
HANDLED_FUNCTIONS = {}
class MyArray:
def __array_function__(self, func, types, args, kwargs):
if func not in HANDLED_FUNCTIONS:
return NotImplemented
# Note: this allows subclasses that don't override
# __array_function__ to handle MyArray objects
if not all(issubclass(t, MyArray) for t in types):
return NotImplemented
return HANDLED_FUNCTIONS[func](*args, **kwargs)
def implements(numpy_function):
"""Register an __array_function__ implementation for MyArray objects."""
def decorator(func):
HANDLED_FUNCTIONS[numpy_function] = func
return func
return decorator
@implements(np.concatenate)
def concatenate(arrays, axis=0, out=None):
... # implementation of concatenate for MyArray objects
@implements(np.broadcast_to)
def broadcast_to(array, shape):
... # implementation of broadcast_to for MyArray objects
Note that it is not required for ``__array_function__`` implementations to
include *all* of the corresponding NumPy function's optional arguments
(e.g., ``broadcast_to`` above omits the irrelevant ``subok`` argument).
Optional arguments are only passed in to ``__array_function__`` if they
were explicitly used in the NumPy function call.
Just like the case for builtin special methods like ``__add__``, properly
written ``__array_function__`` methods should always return
``NotImplemented`` when an unknown type is encountered. Otherwise, it will
be impossible to correctly override NumPy functions from another object
if the operation also includes one of your objects.
For the most part, the rules for dispatch with ``__array_function__``
match those for ``__array_ufunc__``. In particular:
- NumPy will gather implementations of ``__array_function__`` from all
specified inputs and call them in order: subclasses before
superclasses, and otherwise left to right. Note that in some edge cases
involving subclasses, this differs slightly from the
`current behavior <https://bugs.python.org/issue30140>`_ of Python.
- Implementations of ``__array_function__`` indicate that they can
handle the operation by returning any value other than
``NotImplemented``.
- If all ``__array_function__`` methods return ``NotImplemented``,
NumPy will raise ``TypeError``.
If no ``__array_function__`` methods exists, NumPy will default to calling
its own implementation, intended for use on NumPy arrays. This case arises,
for example, when all array-like arguments are Python numbers or lists.
(NumPy arrays do have a ``__array_function__`` method, given below, but it
always returns ``NotImplemented`` if any argument other than a NumPy array
subclass implements ``__array_function__``.)
One deviation from the current behavior of ``__array_ufunc__`` is that
NumPy will only call ``__array_function__`` on the *first* argument of each
unique type. This matches Python's `rule for calling reflected methods
<https://docs.python.org/3/reference/datamodel.html#object.__ror__>`_, and
this ensures that checking overloads has acceptable performance even when
there are a large number of overloaded arguments.
.. py:method:: class.__array_finalize__(obj)
This method is called whenever the system internally allocates a
......
......@@ -8,6 +8,7 @@ C-Types Foreign Function Interface (:mod:`numpy.ctypeslib`)
.. autofunction:: as_array
.. autofunction:: as_ctypes
.. autofunction:: as_ctypes_type
.. autofunction:: ctypes_load_library
.. autofunction:: load_library
.. autofunction:: ndpointer
......@@ -2,6 +2,10 @@
Release Notes
*************
.. include:: ../release/1.16.5-notes.rst
.. include:: ../release/1.16.4-notes.rst
.. include:: ../release/1.16.3-notes.rst
.. include:: ../release/1.16.2-notes.rst
.. include:: ../release/1.16.1-notes.rst
.. include:: ../release/1.16.0-notes.rst
.. include:: ../release/1.15.4-notes.rst
......
.. _basics.dispatch:
*******************************
Writing custom array containers
*******************************
.. automodule:: numpy.doc.dispatch
......@@ -12,4 +12,5 @@ NumPy basics
basics.broadcasting
basics.byteswapping
basics.rec
basics.dispatch
basics.subclassing
......@@ -17,13 +17,13 @@ cache:
before_install:
- sudo apt-get install texlive texlive-latex-extra latexmk
- pip install --upgrade pip setuptools # Upgrade pip and setuptools to get ones with `wheel` support
- pip install --find-links http://wheels.astropy.org/ --find-links http://wheels2.astropy.org/ --trusted-host wheels.astropy.org --trusted-host wheels2.astropy.org --use-wheel nose numpy matplotlib ${SPHINX_SPEC}
- pip install pytest numpy matplotlib ${SPHINX_SPEC}
script:
- |
python setup.py sdist
cd dist
pip install numpydoc* -v
- nosetests numpydoc
- pytest --pyargs numpydoc
- |
cd ../doc
make SPHINXOPTS=$SPHINXOPTS html
......
......@@ -93,7 +93,7 @@ def foo(var1, var2, long_var_name='hi'):
.. math:: X(e^{j\omega } ) = x(n)e^{ - j\omega n}
And even use a greek symbol like :math:`omega` inline.
And even use a Greek symbol like :math:`\omega` inline.
References
----------
......
......@@ -119,6 +119,8 @@ The sections of a function's docstring are:
"""
.. highlight:: rst
2. **Deprecation warning**
A section (use if applicable) to warn users that the object is deprecated.
......@@ -250,13 +252,21 @@ The sections of a function's docstring are:
Support for the **Yields** section was added in `numpydoc
<https://github.com/numpy/numpydoc>`_ version 0.6.
7. **Other Parameters**
7. **Receives**
Explanation of parameters passed to a generator's ``.send()`` method,
formatted as for Parameters, above. Since, like for Yields and Returns, a
single object is always passed to the method, this may describe either the
single parameter, or positional arguments passed as a tuple. If a docstring
includes Receives it must also include Yields.
8. **Other Parameters**
An optional section used to describe infrequently used parameters.
It should only be used if a function has a large number of keyword
parameters, to prevent cluttering the **Parameters** section.
8. **Raises**
9. **Raises**
An optional section detailing which errors get raised and under
what conditions::
......@@ -269,55 +279,55 @@ The sections of a function's docstring are:
This section should be used judiciously, i.e., only for errors
that are non-obvious or have a large chance of getting raised.
9. **Warns**
10. **Warns**
An optional section detailing which warnings get raised and
under what conditions, formatted similarly to Raises.
10. **Warnings**
11. **Warnings**
An optional section with cautions to the user in free text/reST.
An optional section with cautions to the user in free text/reST.
11. **See Also**
12. **See Also**
An optional section used to refer to related code. This section
can be very useful, but should be used judiciously. The goal is to
direct users to other functions they may not be aware of, or have
easy means of discovering (by looking at the module docstring, for
example). Routines whose docstrings further explain parameters
used by this function are good candidates.
An optional section used to refer to related code. This section
can be very useful, but should be used judiciously. The goal is to
direct users to other functions they may not be aware of, or have
easy means of discovering (by looking at the module docstring, for
example). Routines whose docstrings further explain parameters
used by this function are good candidates.
As an example, for ``numpy.mean`` we would have::
As an example, for ``numpy.mean`` we would have::
See Also
--------
average : Weighted average
See Also
--------
average : Weighted average
When referring to functions in the same sub-module, no prefix is
needed, and the tree is searched upwards for a match.
When referring to functions in the same sub-module, no prefix is
needed, and the tree is searched upwards for a match.
Prefix functions from other sub-modules appropriately. E.g.,
whilst documenting the ``random`` module, refer to a function in
``fft`` by
Prefix functions from other sub-modules appropriately. E.g.,
whilst documenting the ``random`` module, refer to a function in
``fft`` by
::
::
fft.fft2 : 2-D fast discrete Fourier transform
fft.fft2 : 2-D fast discrete Fourier transform
When referring to an entirely different module::
When referring to an entirely different module::
scipy.random.norm : Random variates, PDFs, etc.
scipy.random.norm : Random variates, PDFs, etc.
Functions may be listed without descriptions, and this is
preferable if the functionality is clear from the function name::
Functions may be listed without descriptions, and this is
preferable if the functionality is clear from the function name::
See Also
--------
func_a : Function a with its description.
func_b, func_c_, func_d
func_e
See Also
--------
func_a : Function a with its description.
func_b, func_c_, func_d
func_e
12. **Notes**
13. **Notes**
An optional section that provides additional information about the
code, possibly including a discussion of the algorithm. This
......@@ -362,7 +372,7 @@ The sections of a function's docstring are:
where filename is a path relative to the reference guide source
directory.
13. **References**
14. **References**
References cited in the **notes** section may be listed here,
e.g. if you cited the article below using the text ``[1]_``,
......@@ -393,7 +403,9 @@ The sections of a function's docstring are:
docstring, the table markup will be broken by numpydoc processing. See
`numpydoc issue #130 <https://github.com/numpy/numpydoc/issues/130>`_
14. **Examples**
.. highlight:: pycon
15. **Examples**
An optional section for examples, using the `doctest
<http://docs.python.org/library/doctest.html>`_ format.
......@@ -413,6 +425,14 @@ The sections of a function's docstring are:
>>> np.add([1, 2], [3, 4])
array([4, 6])
The example code may be split across multiple lines, with each line after
the first starting with '... '::
>>> np.add([[1, 2], [3, 4]],
... [[5, 6], [7, 8]])
array([[ 6, 8],
[10, 12]])
For tests with a result that is random or platform-dependent, mark the
output as such::
......@@ -456,6 +476,7 @@ The sections of a function's docstring are:
`matplotlib.sphinxext.plot_directive` is loaded as a Sphinx extension in
``conf.py``.
.. highlight:: rst
Documenting classes
-------------------
......@@ -493,7 +514,9 @@ In general, it is not necessary to list class methods. Those that are
not part of the public API have names that start with an underscore.
In some cases, however, a class may have a great many methods, of
which only a few are relevant (e.g., subclasses of ndarray). Then, it
becomes useful to have an additional **Methods** section::
becomes useful to have an additional **Methods** section:
.. code-block:: python
class Photo(ndarray):
"""
......
......@@ -22,3 +22,4 @@ Documentation
install
format
example
validation
==============================
Validating NumpyDoc docstrings
==============================
One tool for validating docstrings is to see how an object's dosctring
translates to Restructured Text. Using numpydoc as a command-line tool
facilitates this. For example to see the Restructured Text generated
for ``numpy.ndarray``, use:
.. code-block:: bash
$ python -m numpydoc numpy.ndarray
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment