<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/python-packages/numpy.git/numpy/core/overrides.py, branch dependabot/pip/gitpython-3.1.14</title>
<subtitle>github.com: numpy/numpy.git
</subtitle>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/'/>
<entry>
<title>ENH: implement NEP-35's `like=` argument (gh-16935)</title>
<updated>2020-08-28T18:05:18+00:00</updated>
<author>
<name>Peter Andreas Entschev</name>
<email>peter@entschev.com</email>
</author>
<published>2020-08-28T18:05:18+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=4cd6e4b336fbc68d88c0e9bc45a435ce7b721f1f'/>
<id>4cd6e4b336fbc68d88c0e9bc45a435ce7b721f1f</id>
<content type='text'>
This PR adds the implementation of NEP-35's like= argument, allowing dispatch of array creation functions with __array_function__ based on a reference array.

* ENH: Add like= kwarg via __array_function__ dispatcher to asarray

* ENH: Add new function for __array_function__ dispatching from C

This new function allows dispatching from C directly, while also
implementing the new `like=` argument, requiring only minimal
changes to existing array creation functions that need to add
support for that argument.

* ENH: Add like= support to numpy.array

The implementation uses array_implement_c_array_function, thus
introducing minimal complexity to the original _array_fromobject
code.

* BUG: Fix like= dispatcher for np.full

* ENH: Remove np.asarray like= dispatcher via Python

np.asarray can rely on np.array's C dispatcher instead.

* TST: Add some tests for like= argument

Tests comprise some of the functions that have been implemented already:
* np.array (C dispatcher)
* np.asarray (indirect C dispatcher via np.array)
* np.full (Python dispatcher)
* np.ones (Python dispatcher)

* ENH: Remove like= argument during array_implement_array_function

* ENH: Add like= kwarg to ones and full

* BUG: prevent duplicate removal of `like=` argument

* ENH: Make `like=` a keyword-only argument

* ENH: Use PyUnicode_InternFromString in arrayfunction_override

Replace PyUnicode_FromString by PyUnicode_InternFromString to cache
"like" string.

* ENH: Check for arrayfunction_override import errors

Check and handle errors on importing NumPy's Python functions

* BUG: Fix array_implement_c_array_function error handling

* ENH: Handle exceptions with C implementation of `like=`

* ENH: Add `like=` dispatch for all asarray functions

Using Python dispatcher for all of them. Using the C dispatcher
directly on the `np.array` call can result in incorrect behavior.
Incorrect behavior may happen if the downstream library's
implementation is different or if not all keyword arguments are
supported.

* ENH: Simplify handling of exceptions with `like=`

* TST: Add test for exception handling with `like=`

* ENH: Add support for `like=` to `np.empty` and `np.zeros`

* TST: Add `like=` tests for `np.empty` and `np.zeros`

* ENH: Add `like=` to remaining multiarraymodule.c functions

Functions are:
* np.arange
* np.frombuffer
* np.fromfile
* np.fromiter
* np.fromstring

* TST: Add tests for multiarraymodule.c functions with like=

Functions are:
* np.arange
* np.frombuffer
* np.fromfile
* np.fromiter
* np.fromstring

* ENH: Add `like=` support to more creation functions

Support for the following functions is added:
* np.eye
* np.fromfunction
* np.genfromtxt
* np.identity
* np.loadtxt
* np.tri

* TST: Add `like=` tests for multiple functions

Tests for the following functions are added:
* np.eye
* np.fromfunction
* np.genfromtxt
* np.identity
* np.loadtxt
* np.tri

* TST: Reduce code duplication in `like=` tests

* DOC: Document `like=` in functions that support it

Add documentations for the following functions:
* np.array
* np.arange
* np.asarray
* np.asanyarray
* np.ascontiguousarray
* np.asfortranarray
* np.require
* np.empty
* np.full
* np.ones
* np.zeros
* np.identity
* np.eye
* np.tri
* np.frombuffer
* np.fromfile
* np.fromiter
* np.fromstring
* np.loadtxt
* np.genfromtxt

* ENH: Add `like=` to numpy/__init__.pyi stubs

* BUG: Remove duplicate `like=` dispatching in as*array

Functions `np.asanyarray`, `np.contiguousarray` and `np.fortranarray`
were dispatching both via their definitions and `np.array` calls,
the latter should be avoided.

* BUG: Fix missing check in array_implement_array_function

* BUG: Add missing keyword-only markers in stubs

* BUG: Fix duplicate keyword-only marker in array stub

* BUG: Fix syntax error in numpy/__init__.pyi

* BUG: Fix more syntax errors in numpy/__init__.pyi

* ENH: Intern arrayfunction_override strings in multiarraymodule

* STY: Add missing brackets to arrayfunction_override.c

* MAINT: Remove arrayfunction_override dict check for kwarg

* TST: Assert that 'like' is not in TestArrayLike kwargs

* MAINT: Rename array_implement_c_array_function(_creation)

This is done to be more explicit as to its usage being intended for
array creation functions only.

* MAINT: Use NotImplemented to indicate fallback to default

* TST: Test that results with `like=np.array` are correct

* TST: Avoid duplicating MyArray code in TestArrayLike

* TST: Don't delete temp file, it may cause issues with Windows

* TST: Don't rely on eval in TestArrayLike

* TST: Use lambda with StringIO in TestArrayLike

* ENH: Avoid unnecessary Py_XDECREF in arrayfunction_override

* TST: Make TestArrayLike more readable

* ENH: Cleaner error handling in arrayfunction_override

* ENH: Simplify array_implement_c_array_function_creation

* STY: Add missing spaces to multiarraymodule.c

* STY: C99 declaration style in arrayfunction_override.c

* ENH: Simplify arrayfunction_override.c further

Remove cleanup label from array_implementation_c_array_function,
simplifying the code. Fix unitialized variable warning in
array_implementation_array_function_internal.

* DOC: Use string replacement for `like=` documentation

Avoid repeating the full text for the `like=` argument by storing it as
a variable and using `replace` on each docstring.

* DOC: Update `like=` docstring

* TST: Test like= with array not implementing __array_function__

* TST: Add missing asanyarray to TestArrayLike

* ENH: Use helper function for like= dispatching

Avoid dispatching like= from Python implementation functions to improve
their performance. This is achieved by only calling a dispatcher
function when like is passed by the users.

* ENH: Rename array_function_dispatch kwarg to public_api

* BUG: Add accidentally removed decorator for np.eye back

* DOC: Add set_array_function_like_doc function

The function keeps Python files cleaner and resolve errors when __doc__
is not defined due to PYTHONOPTIMIZE or -OO .

* DOC: Add mention to like= kwarg being experimental

* TST: Test like= with not implemented downstream function

* DOC: Fix like= docstring reference to NEP 35.

* ENH: Prevent silent errors if public_api is not callable

* ENH: Make set_array_function_like_doc a decorator

* ENH: Simplify `_*_with_like` functions

* BUG: Fix multiple `like=` dispatching in `require`

* MAINT: Remove now unused public_api from array_function_dispatch

Co-authored-by: Sebastian Berg &lt;sebastian@sipsolutions.net&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This PR adds the implementation of NEP-35's like= argument, allowing dispatch of array creation functions with __array_function__ based on a reference array.

* ENH: Add like= kwarg via __array_function__ dispatcher to asarray

* ENH: Add new function for __array_function__ dispatching from C

This new function allows dispatching from C directly, while also
implementing the new `like=` argument, requiring only minimal
changes to existing array creation functions that need to add
support for that argument.

* ENH: Add like= support to numpy.array

The implementation uses array_implement_c_array_function, thus
introducing minimal complexity to the original _array_fromobject
code.

* BUG: Fix like= dispatcher for np.full

* ENH: Remove np.asarray like= dispatcher via Python

np.asarray can rely on np.array's C dispatcher instead.

* TST: Add some tests for like= argument

Tests comprise some of the functions that have been implemented already:
* np.array (C dispatcher)
* np.asarray (indirect C dispatcher via np.array)
* np.full (Python dispatcher)
* np.ones (Python dispatcher)

* ENH: Remove like= argument during array_implement_array_function

* ENH: Add like= kwarg to ones and full

* BUG: prevent duplicate removal of `like=` argument

* ENH: Make `like=` a keyword-only argument

* ENH: Use PyUnicode_InternFromString in arrayfunction_override

Replace PyUnicode_FromString by PyUnicode_InternFromString to cache
"like" string.

* ENH: Check for arrayfunction_override import errors

Check and handle errors on importing NumPy's Python functions

* BUG: Fix array_implement_c_array_function error handling

* ENH: Handle exceptions with C implementation of `like=`

* ENH: Add `like=` dispatch for all asarray functions

Using Python dispatcher for all of them. Using the C dispatcher
directly on the `np.array` call can result in incorrect behavior.
Incorrect behavior may happen if the downstream library's
implementation is different or if not all keyword arguments are
supported.

* ENH: Simplify handling of exceptions with `like=`

* TST: Add test for exception handling with `like=`

* ENH: Add support for `like=` to `np.empty` and `np.zeros`

* TST: Add `like=` tests for `np.empty` and `np.zeros`

* ENH: Add `like=` to remaining multiarraymodule.c functions

Functions are:
* np.arange
* np.frombuffer
* np.fromfile
* np.fromiter
* np.fromstring

* TST: Add tests for multiarraymodule.c functions with like=

Functions are:
* np.arange
* np.frombuffer
* np.fromfile
* np.fromiter
* np.fromstring

* ENH: Add `like=` support to more creation functions

Support for the following functions is added:
* np.eye
* np.fromfunction
* np.genfromtxt
* np.identity
* np.loadtxt
* np.tri

* TST: Add `like=` tests for multiple functions

Tests for the following functions are added:
* np.eye
* np.fromfunction
* np.genfromtxt
* np.identity
* np.loadtxt
* np.tri

* TST: Reduce code duplication in `like=` tests

* DOC: Document `like=` in functions that support it

Add documentations for the following functions:
* np.array
* np.arange
* np.asarray
* np.asanyarray
* np.ascontiguousarray
* np.asfortranarray
* np.require
* np.empty
* np.full
* np.ones
* np.zeros
* np.identity
* np.eye
* np.tri
* np.frombuffer
* np.fromfile
* np.fromiter
* np.fromstring
* np.loadtxt
* np.genfromtxt

* ENH: Add `like=` to numpy/__init__.pyi stubs

* BUG: Remove duplicate `like=` dispatching in as*array

Functions `np.asanyarray`, `np.contiguousarray` and `np.fortranarray`
were dispatching both via their definitions and `np.array` calls,
the latter should be avoided.

* BUG: Fix missing check in array_implement_array_function

* BUG: Add missing keyword-only markers in stubs

* BUG: Fix duplicate keyword-only marker in array stub

* BUG: Fix syntax error in numpy/__init__.pyi

* BUG: Fix more syntax errors in numpy/__init__.pyi

* ENH: Intern arrayfunction_override strings in multiarraymodule

* STY: Add missing brackets to arrayfunction_override.c

* MAINT: Remove arrayfunction_override dict check for kwarg

* TST: Assert that 'like' is not in TestArrayLike kwargs

* MAINT: Rename array_implement_c_array_function(_creation)

This is done to be more explicit as to its usage being intended for
array creation functions only.

* MAINT: Use NotImplemented to indicate fallback to default

* TST: Test that results with `like=np.array` are correct

* TST: Avoid duplicating MyArray code in TestArrayLike

* TST: Don't delete temp file, it may cause issues with Windows

* TST: Don't rely on eval in TestArrayLike

* TST: Use lambda with StringIO in TestArrayLike

* ENH: Avoid unnecessary Py_XDECREF in arrayfunction_override

* TST: Make TestArrayLike more readable

* ENH: Cleaner error handling in arrayfunction_override

* ENH: Simplify array_implement_c_array_function_creation

* STY: Add missing spaces to multiarraymodule.c

* STY: C99 declaration style in arrayfunction_override.c

* ENH: Simplify arrayfunction_override.c further

Remove cleanup label from array_implementation_c_array_function,
simplifying the code. Fix unitialized variable warning in
array_implementation_array_function_internal.

* DOC: Use string replacement for `like=` documentation

Avoid repeating the full text for the `like=` argument by storing it as
a variable and using `replace` on each docstring.

* DOC: Update `like=` docstring

* TST: Test like= with array not implementing __array_function__

* TST: Add missing asanyarray to TestArrayLike

* ENH: Use helper function for like= dispatching

Avoid dispatching like= from Python implementation functions to improve
their performance. This is achieved by only calling a dispatcher
function when like is passed by the users.

* ENH: Rename array_function_dispatch kwarg to public_api

* BUG: Add accidentally removed decorator for np.eye back

* DOC: Add set_array_function_like_doc function

The function keeps Python files cleaner and resolve errors when __doc__
is not defined due to PYTHONOPTIMIZE or -OO .

* DOC: Add mention to like= kwarg being experimental

* TST: Test like= with not implemented downstream function

* DOC: Fix like= docstring reference to NEP 35.

* ENH: Prevent silent errors if public_api is not callable

* ENH: Make set_array_function_like_doc a decorator

* ENH: Simplify `_*_with_like` functions

* BUG: Fix multiple `like=` dispatching in `require`

* MAINT: Remove now unused public_api from array_function_dispatch

Co-authored-by: Sebastian Berg &lt;sebastian@sipsolutions.net&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>DOC: Fix RST/numpydoc standard.</title>
<updated>2020-07-10T20:24:30+00:00</updated>
<author>
<name>Matthias Bussonnier</name>
<email>bussonniermatthias@gmail.com</email>
</author>
<published>2020-07-10T20:24:30+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=7eb261d028f0f31c4851ea19f17c9c36c616009c'/>
<id>7eb261d028f0f31c4851ea19f17c9c36c616009c</id>
<content type='text'>
One of the header line was not long enough, make it the same length as
the title.

The section "Arguments" is usually called "Parameters". Update for
consistency.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
One of the header line was not long enough, make it the same length as
the title.

The section "Arguments" is usually called "Parameters". Update for
consistency.
</pre>
</div>
</content>
</entry>
<entry>
<title>MAINT: import time: avoid repeated textwrap function dispatch instantiation</title>
<updated>2019-07-26T00:46:13+00:00</updated>
<author>
<name>Mark Harfouche</name>
<email>mark.harfouche@gmail.com</email>
</author>
<published>2019-07-26T00:46:13+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=702c357536c23d8122fe152f0d86b9add1add6a0'/>
<id>702c357536c23d8122fe152f0d86b9add1add6a0</id>
<content type='text'>
Avoid the repeated call of `dedent` when a single call is enough. This micro-optimizes
the import time from around 100ms (or slightly above) by 4-6 ms. (PR: gh-14095)</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Avoid the repeated call of `dedent` when a single call is enough. This micro-optimizes
the import time from around 100ms (or slightly above) by 4-6 ms. (PR: gh-14095)</pre>
</div>
</content>
</entry>
<entry>
<title>MAINT: Fixes tests with __array_function__ disabled</title>
<updated>2019-05-26T19:04:44+00:00</updated>
<author>
<name>Stephan Hoyer</name>
<email>shoyer@google.com</email>
</author>
<published>2019-05-26T19:04:44+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=9216a1dd5391013bf0670bb3d9d07ef68c3b7d66'/>
<id>9216a1dd5391013bf0670bb3d9d07ef68c3b7d66</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Tests for NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=0</title>
<updated>2019-05-25T23:18:59+00:00</updated>
<author>
<name>Stephan Hoyer</name>
<email>shoyer@google.com</email>
</author>
<published>2019-05-25T23:18:59+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=37df5e641f19d9e5221cb519532b6cc5647ebe53'/>
<id>37df5e641f19d9e5221cb519532b6cc5647ebe53</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>MAINT: revert __skip_array_function__ from NEP-18</title>
<updated>2019-05-25T22:05:59+00:00</updated>
<author>
<name>Stephan Hoyer</name>
<email>shoyer@google.com</email>
</author>
<published>2019-05-25T22:05:59+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=766281d1bef8845407855ddf48e3d6b50668e7b7'/>
<id>766281d1bef8845407855ddf48e3d6b50668e7b7</id>
<content type='text'>
xref GH-13624, GH-12028

TODO: update tests/CI for NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=0
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
xref GH-13624, GH-12028

TODO: update tests/CI for NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=0
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'master' into implement-numpy-implementation</title>
<updated>2019-05-13T15:09:26+00:00</updated>
<author>
<name>Stephan Hoyer</name>
<email>shoyer@google.com</email>
</author>
<published>2019-05-13T15:09:26+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=07452c86c78a1cf213a764d17f060b4887ec3681'/>
<id>07452c86c78a1cf213a764d17f060b4887ec3681</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>ENH: invent a better fake filename than '&lt;string'&gt;</title>
<updated>2019-05-11T19:44:54+00:00</updated>
<author>
<name>Stephan Hoyer</name>
<email>shoyer@google.com</email>
</author>
<published>2019-05-11T19:44:54+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=9055d2175f1dc509aa3025ea01546e6de689277f'/>
<id>9055d2175f1dc509aa3025ea01546e6de689277f</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>ENH: use exec() instead array_function_dispatch to improve tracebacks</title>
<updated>2019-05-11T19:25:45+00:00</updated>
<author>
<name>Stephan Hoyer</name>
<email>shoyer@google.com</email>
</author>
<published>2019-05-11T19:20:12+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=34bca67c9c918e90db4b33336a1d9ed2a57350d4'/>
<id>34bca67c9c918e90db4b33336a1d9ed2a57350d4</id>
<content type='text'>
xref GH-12028

Current behavior:

&gt;&gt;&gt; np.dot(None, None)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/Users/shoyer/dev/numpy/numpy/core/overrides.py", line 175, in public_api
    implementation, public_api, relevant_args, args, kwargs)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

&gt;&gt;&gt; np.stack([], invalid=True)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/Users/shoyer/dev/numpy/numpy/core/overrides.py", line 148, in public_api
    relevant_args = dispatcher(*args, **kwargs)
TypeError: _stack_dispatcher() got an unexpected keyword argument 'invalid'

With this change:

&gt;&gt;&gt; np.dot(None, None)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;string&gt;", line 6, in dot
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

&gt;&gt;&gt; np.stack([], invalid=True)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;string&gt;", line 4, in stack
TypeError: _stack_dispatcher() got an unexpected keyword argument 'invalid'
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
xref GH-12028

Current behavior:

&gt;&gt;&gt; np.dot(None, None)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/Users/shoyer/dev/numpy/numpy/core/overrides.py", line 175, in public_api
    implementation, public_api, relevant_args, args, kwargs)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

&gt;&gt;&gt; np.stack([], invalid=True)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/Users/shoyer/dev/numpy/numpy/core/overrides.py", line 148, in public_api
    relevant_args = dispatcher(*args, **kwargs)
TypeError: _stack_dispatcher() got an unexpected keyword argument 'invalid'

With this change:

&gt;&gt;&gt; np.dot(None, None)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;string&gt;", line 6, in dot
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

&gt;&gt;&gt; np.stack([], invalid=True)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;string&gt;", line 4, in stack
TypeError: _stack_dispatcher() got an unexpected keyword argument 'invalid'
</pre>
</div>
</content>
</entry>
<entry>
<title>Rename to __skip_array_function__</title>
<updated>2019-05-11T00:25:52+00:00</updated>
<author>
<name>Stephan Hoyer</name>
<email>shoyer@google.com</email>
</author>
<published>2019-05-11T00:25:52+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/python-packages/numpy.git/commit/?id=804f71bb42fef775a85a52366dc4bd1a22c130a8'/>
<id>804f71bb42fef775a85a52366dc4bd1a22c130a8</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
