I found the following behavior a bit unexpected from the name of the argument.
The default (
copy=False
) may return a copy instead of a view.copy=True
always returns a copy, butcopy=False
does not always return a view.
I think changing the argument name to something like always_copy
would be more clear about what it is doing.
Comment From: attack68
-1, whilst what you are proposing might be clearer, I consider the existing docs explicitly clear enough. Perhaps expanding:
copy=False
does not always return a view and still may return a copy depending upon object type.
Comment From: mzeitlin11
Agreed with @attack68, this conditional copying mirrors numpy
behavior as well, for example in https://numpy.org/doc/stable/reference/generated/numpy.array.html
If true (default), then the object is copied. Otherwise, a copy will only be made if array returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.).
Comment From: jorisvandenbossche
Small note that in numpy they have been discussing changing the arguments for this keyword, cfr https://github.com/numpy/numpy/pull/19173 (and mailing list discussions), to be able to distinguish those cases of "never coying" vs "only copy when needed"
Comment From: simonjayhawkins
for EAs the backing data may not necessarily be a NumPy array, so it is not always possible to return a view from to_numpy
.
So we can't necessarily make the behavior of copy
align with NumPy semantics. That said, +1 on leaving as is for now and await the outcome of the Numpy discussion.
Comment From: Abdelgha-4
NumPy discussion about this has been ended in numpy/numpy#19173, so I guess we could make a decision about this issue now ?