Repository navigation
Conversation
|
|
||
| @array_function_dispatch(_append_dispatcher) | ||
| def append(arr, values, axis=None): | ||
| def append(arr, values, dtype=None, axis=None): |
There was a problem hiding this comment.
The documentation for append needs to be updated to explain what the dtype parameter is.
There was a problem hiding this comment.
@MatteoRaso I added the parameter to the function documentation.
There was a problem hiding this comment.
dtype must be the last parameter, to not break users who currently wrote: np.append(arr, 1, 0)
dtype argument to np.append
There was a problem hiding this comment.
The idea is good, although I am a bit unsure if we should go down this road, because I do agree with the initial reporter that it is confusing that append uses the "common dtype" and promotes both arrays (like concatenate).
EDIT: Just editing. But it also needs some basic tests.
| if arr.ndim != 1: | ||
| arr = arr.ravel() | ||
| values = ravel(values) | ||
| axis = arr.ndim-1 |
There was a problem hiding this comment.
We could delete all of this code I think. concatenate supports axis=None in exactly this way already? I am wondering why it is there, but it may well out-date NumPy itself...
Mainly, casting arr to dtype ahead of time is also unnecessary.
There was a problem hiding this comment.
@seberg I delete the checking dtype if None code. I also found it unnecessary and only depended on passing the dtype to the concatenate function.
|
|
||
| @array_function_dispatch(_append_dispatcher) | ||
| def append(arr, values, axis=None): | ||
| def append(arr, values, dtype=None, axis=None): |
There was a problem hiding this comment.
dtype must be the last parameter, to not break users who currently wrote: np.append(arr, 1, 0)
|
This needs tests and a release note. |
|
This seems to have stranded, so I'm going to close it. We can re-open if you still want to work on this @maidaly |
This pull request is for solving the #22427 issue. I solved it by adding a new parameter
dtypeto the append function so it can overwrite the defaultdtypein the generated copy from the array which has not the same type as the original one .