4 ms·
I agree with you in spirit. Having separate names is preferable to context-specific semantics for the []. In pandas, using [] alone is discouraged, in favor of
by superbatfish 5y ago
I agree with you in spirit. Having separate names is preferable to context-specific semantics for the []. In pandas, using [] alone is discouraged, in favor of using .loc or .iloc. But admittedly, that only partially improves the situation. Both accept multiple types (int vs int-list vs bool-list).
Last year, I had an in-person discussion with a numpy core developer in which I proposed adding pandas-like syntax to numpy, e.g. allowing the author to use:
a.boolmask[b == c]
(but maybe not so verbose).
A problem immediately arises: An array can have multiple axes, and each could be indexed with a different type within the same slicing call.
One idea might be to allow the author to explicitly wrap the arguments with some dummy class to make clear what types they’re using:
a[np.boolmask(b == c), d, np.intlist(e)]
(Again, perhaps choosing shorter names in practice.)
The idea would be that the wrapper merely “looks like” the thing it wraps, but contains an assertion to verify the type of the argument.
Anyway, I agree that notebooks (or REPLs in general) are great for verifying your assumptions about how little snippets will behave. But I think they would be useful even in a fully statically-typed compiled language, too.