Proposed erratum to clarify arraysize="1"

Markus Demleitner msdemlei at ari.uni-heidelberg.de
Fri Feb 16 09:31:20 CET 2018


Hi Apps,

On Thu, Feb 15, 2018 at 04:31:37PM +0000, Tom Donaldson wrote:
> As a side note, I agree that STIL/TOPCAT does do the sensible
> thing.  ???  For astropy however, it???s worth noting that although
> it treats arraysize=???1??? cases as ???arrays???, those arrays
> offer flexibility within the astropy/numpy framework that ends up
> treating the value as a scalar when one is needed.
> 
> As a simple example, this output:
> 
> One value is an array, the other is a scalar.
> f1 value = [1] (arraysize="1")
> f2 value = 1   (scalar)
> 
[...]
> 
> I expect that the main problems come up in cases where it???s not
> clear a scalar is expected, such as re-serialization for sharing
> with other consumers.

Unfortunately, that's not quite true.  Things quickly become ugly
when you have arrays of these beasts (as in: a column).  For
instance, when constructing coordinates.SkyCoords, I had (a while
ago) to write:

  def work_around_arraysize1(col):
    if not np.isscalar(col[0]) and col[0].shape==(1,):
      return col.__class__(data=col[:,0], name=col.name, mask=col.mask[:,0],
        unit=col.unit, meta=col.meta)
    else:
      return col

  coords = coordinates.SkyCoord(
    work_around_arraysize1(table[ra_column]), 
    work_around_arraysize1(table[dec_column]))

-- and I seem to remember the diagnostics astropy produces without
this workaround weren't really helpful.  Either way, that's certainly
not the sort of code I'd ask Joe Astronomer to write.

         -- Markus


More information about the apps mailing list