LSSTDESC/healsparse

Boolean maps can't be filled with booleans

Closed this issue · 2 comments

Here's a fun one...

>>> map_bool = hsp.HealSparseMap.make_empty(32, 16384, np.bool)
>>> map_bool
HealSparseMap: nside_coverage = 32, nside_sparse = 16384, bool
>>> map_bool[0] = True
ValueError                                Traceback (most recent call last)
<ipython-input-10-0edf9ce03ec2> in <module>
----> 1 map_bool[0] =  True

/cvmfs/des.opensciencegrid.org/fnal/anaconda2/envs/des20a/lib/python3.7/site-packages/healsparse/healSparseMap.py in __setitem__(self, key, value)
   1421         if isinstance(key, int):
   1422             # Set a single pixel
-> 1423             return self.update_values_pix(np.array([key]), value)
   1424         elif isinstance(key, slice):
   1425             # Set a slice of pixels

/cvmfs/des.opensciencegrid.org/fnal/anaconda2/envs/des20a/lib/python3.7/site-packages/healsparse/healSparseMap.py in update_values_pix(self, pixels, values, nest, operation)
    570                 if isinstance(values, numbers.Integral):
    571                     if not self.is_integer_map:
--> 572                         raise ValueError("Cannot set non-integer map with an integer")
    573                     is_single_value = True
    574                     _values = np.array([values], dtype=self.dtype)

ValueError: Cannot set non-integer map with an integer

However, everyone seems happy with map_bool[0] = float(True). Probably need to define is_boolean_map or hack is_integer_map to be True for boolean maps.

Looks like the sentinel values for boolean maps are also messed up (they should be False instead of None):

>>> hsp.HealSparseMap.make_empty(32, 16384, np.bool)._sentinel is None           
True

Fixed on #129