summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorRoss Barnowski <rossbar@berkeley.edu>2020-03-11 10:53:27 -0700
committerGitHub <noreply@github.com>2020-03-11 10:53:27 -0700
commitb074b21c326ecaa6b6519fc7dfcf54fa4e4457af (patch)
tree37c463c354ec01c54f01bd6070ba96166ebb3211 /numpy/lib/function_base.py
parent59a97520cf0aa68b92a775d809e1cb67d886b50c (diff)
downloadnumpy-b074b21c326ecaa6b6519fc7dfcf54fa4e4457af.tar.gz
ENH: Add `subok` parameter to np.copy function (cf. gfh6509) (gh-15685)
This is largely a re-submission of the original change proposed in #6509. Discussion was hosted in multiple forums including #3474, the numpy mailing list circa 10-2015, and the 02-26-2020 NumPy Triage meeting. This PR closes #3474 and #15570
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 47b5133be..b9f3bbb16 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -708,12 +708,12 @@ def select(condlist, choicelist, default=0):
return result
-def _copy_dispatcher(a, order=None):
+def _copy_dispatcher(a, order=None, subok=None):
return (a,)
@array_function_dispatch(_copy_dispatcher)
-def copy(a, order='K'):
+def copy(a, order='K', subok=False):
"""
Return an array copy of the given object.
@@ -728,12 +728,21 @@ def copy(a, order='K'):
as possible. (Note that this function and :meth:`ndarray.copy` are very
similar, but have different default values for their order=
arguments.)
+ subok : bool, optional
+ If True, then sub-classes will be passed-through, otherwise the
+ returned array will be forced to be a base-class array (defaults to False).
+
+ .. versionadded:: 1.19.0
Returns
-------
arr : ndarray
Array interpretation of `a`.
+ See Also
+ --------
+ ndarray.copy : Preferred method for creating an array copy
+
Notes
-----
This is equivalent to:
@@ -757,7 +766,7 @@ def copy(a, order='K'):
False
"""
- return array(a, order=order, copy=True)
+ return array(a, order=order, subok=subok, copy=True)
# Basic operations