[Numpy-discussion] missing data discussion round 2
Wed Jun 29 12:22:59 CDT 2011
On Wed, Jun 29, 2011 at 8:20 AM, Lluís <email@example.com> wrote:
> Matthew Brett writes:
> >> Maybe instead of np.NA, we could say np.IGNORE, which sort of conveys
> >> the idea that the entry is still there, but we're just ignoring it. Of
> >> course, that goes against common convention, but it might be easier to
> >> explain.
> > I think Nathaniel's point is that np.IGNORE is a different idea than
> > np.NA, and that is why joining the implementations can lead to
> > conceptual confusion.
> This is how I see it:
> >>> a = np.array([0, 1, 2], dtype=int)
> >>> a = np.NA
> >>> e = np.array([np.NA, 1, 2], dtype=int)
> >>> b = np.array([np.NA, 1, 2], dtype=np.maybe(int))
> >>> m = np.array([np.NA, 1, 2], dtype=int, masked=True)
> >>> bm = np.array([np.NA, 1, 2], dtype=np.maybe(int), masked=True)
> >>> b = np.NA
> >>> np.sum(b)
> >>> np.sum(b, skipna=True)
> >>> b.mask
> >>> m = np.NA
> >>> np.sum(m)
> >>> np.sum(m, skipna=True)
> >>> m.mask
> [False, False, True]
> >>> bm = np.NA
> >>> np.sum(bm)
> >>> np.sum(bm, skipna=True)
> >>> bm.mask
> [False, False, True]
> * Mask takes precedence over bit pattern on element assignment. There's
> still the question of how to assign a bit pattern NA when the mask is
> * When using mask, elements are automagically skipped.
> * "m = np.NA" is equivalent to "m.mask = False"
> * When using bit pattern + mask, it might make sense to have the initial
> values as bit-pattern NAs, instead of masked (i.e., "bm.mask == [True,
> False, True]" and "np.sum(bm) == np.NA")
There seems to be a general idea that masks and NA bit patterns imply
particular differing semantics, something which I think is simply false.
Both NaN and Inf are implemented in hardware with the same idea as the NA
bit pattern, but they do not follow NA missing value semantics.
As far as I can tell, the only required difference between them is that NA
bit patterns must destroy the data. Nothing else. Everything on top of that
is a choice of API and interface mechanisms. I want them to behave exactly
the same except for that necessary difference, so that it will be possible
to use the *exact same Python code* with either approach.
Say you're using NA dtypes, and suddenly you think, "what if I temporarily
treated these as NA too". Now you have to copy your whole array to avoid
destroying your data! The NA bit pattern didn't save you memory here... Say
you're using masks, and it turns out you didn't actually need masking
semantics. If they're different, you now have to do lots of code changes to
switch to NA dtypes!
> "And it's much the same thing with knowledge, for whenever you learn
> something new, the whole world becomes that much richer."
> -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
> NumPy-Discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion