On June 12, 2013 at 14:10:27, Nathaniel Smith (njs@pobox.com) wrote:
Hi all,
It looks like we've gotten a bit confused and need to untangle
something. There's a PR to add new functions 'np.filled' and
'np.filled_like':
https://github.com/numpy/numpy/pull/2875
And there was a discussion about this on the list back in January:
http://thread.gmane.org/gmane.comp.python.numeric.general/52763
I think a reasonable summary of the opinions in the thread are:
- This functionality is great, ...
- ...but we can't call it 'np.filled' because there's also
'np.ma.filled' which does something else...
I don't think this is a problem, is it? Different namespaces
Personally I think that overloading np.empty is horribly ugly, will
continue confusing newbies and everyone else indefinitely, and I'm
100% convinced that we'll regret implementing such a warty interface
for something that should be so idiomatic. (Unfortunately I got busy
and didn't actually say this in the previous thread though.) So I
think we should just merge the PR as is. The only downside is the
np.ma inconsistency, but, np.ma is already inconsistent (cf.
masked_array.fill versus masked_array.filled!), somewhat deprecated,
in np.ma, `.fill` is directly inherited of ndarray: *all* the elements are replaced by some value. `.filled` is completely different beast, replacing *only the masked entries* by a filling value. The name `.filled` was kept for backward compatibility with the original implementation (we're talking pre 1.2, the one inherited from numarray)
and AFAICT there are far more people who will benefit from a clean
np.filled idiom than who actually use np.ma (and in particular its
fill-value functionality). So there would be two
bad-but-IMHO-acceptable options: either live with an inconsistency
between np.filled and np.ma.filled, or deprecate np.ma.filled in favor
of masked_array.filled (which does exactly the same thing) and
eventually switch np.ma.filled to be consistent with the new
np.filled.
But, that's just my opinion.
Not that I have any strong opinion about that, but the inconsistency looks better (less worse) to me than changing the behaviour of `np.ma.filled`. After all, the name of the function says it all: it fills the holes in a masked array. Anyhow, given my level of involvement these days (month/years), I'll go along a consensus