[Numpy-discussion] new NEP: np.AbstractArray and np.asabstractarray

Marten van Kerkwijk m.h.vankerkwijk at gmail.com
Fri Mar 9 17:49:21 EST 2018


We may be getting a bit distracted by the naming -- though I'll throw
out `asarraymimic` as another non-programmer-lingo option that doesn't
reuse `arraylike` and might describe what the duck array is attempting
to do more closely.

But more to the point: I think in essence, we're trying to create a
function that does the equivalent of:
```
def ...(arraylike, ...)
    if isinstance(arraylike, NDAbstractArray):
        return arraylike
    else:
        return np.array(arraylike, ...)
```

Given that one possibly might want to check for partial compatibility,
maybe the new or old function should just expose what compatibility is
desired, via something like:
```
input = np.as...(input, ..., mimicok='shape|operator|...')
```
Where one could have `mimicok=True` to indicate the highest level
(maybe not including being viewable?), `False` to not allow any
mimics.

This might even work for np.array itself:
- dtype - any mimic must provide `astype` (which can error if not
possible; this could be the ABC default)
- copy - can't one just use `copy.copy`? I think this defaults to `__copy__`.
- order - can be passed to `astype` as well; up to code to error if
not possible.
- subok - meaningless
- ndmin - requirement of mimicok='shape' would be to provide a shape
attribute and reshape method.

-- Marten


More information about the NumPy-Discussion mailing list