[Numpy-discussion] Add guaranteed no-copy to array creation and reshape?

Nathaniel Smith njs at pobox.com
Thu Dec 27 20:45:58 EST 2018


On Thu, Dec 27, 2018 at 3:27 PM Juan Nunez-Iglesias <jni.soma at gmail.com> wrote:
>
> On Fri, Dec 28, 2018, at 3:40 AM, Sebastian Berg wrote:
>
> > It’s consistent with np.newaxis in spelling (modulo the _)
> > If mistyped, it can be caught easily by IDEs.
> > It’s typeable with mypy, unlike constant string literals which
> > currently aren’t
> > If code written against new numpy is run on old numpy, it will error
> > rather than doing the wrong thing
>
> I am not sure I think that the above are too strong arguments, since it
> is not what is typically done for keywords (nobody suggests np.CLIP
> instead of "clip"). Unless you feel this is different because it is a
> mix of strings and bools here?
>
>
> :+1: to Eric's list. I don't think it's different because of the mix, I think it's different because deprecating things is painful. But now that we have good typing in Python, I think of string literals as an anti-pattern going forward.

I've certainly seen people argue that it's better to use proper enum's
in this kind of case instead of strings. The 'enum' package is even
included in the stdlib on all our supported versions now:
https://docs.python.org/3/library/enum.html

I guess another possibility to throw out there would be a second
kwarg, require_view=False/True.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the NumPy-Discussion mailing list