NCPP / ocgis

OpenClimateGIS is a set of geoprocessing and calculation tools for CF-compliant climate datasets.
Other
70 stars 19 forks source link

DimensionMap.set_spatial_mask attrs handling #455

Closed huard closed 7 years ago

huard commented 7 years ago

Minor bug that is not triggered by any code at this point, but the attrs argument is overwritten by either default_attrs or variable.attrs. Is this intended?

    def set_spatial_mask(self, variable, attrs=None):
        """
        Set the spatial mask variable for the dimension map.

        :param variable: The spatial mask variable.
        :param dict attrs: Attribute associated with the spatial mask variable.
        :type variable: :class:`~ocgis.Variable` | :class:`str`
        """

        default_attrs = DIMENSION_MAP_TEMPLATE[DMK.SPATIAL_MASK][DMK.ATTRS]

        if attrs is None:
            attrs = default_attrs
        else:
            try:
                attrs = deepcopy(variable.attrs)
            except AttributeError:
                attrs = default_attrs
            else:
                attrs.update(default_attrs)

        variable = get_variable_names(variable)[0]
        entry = self._get_entry_(DMK.SPATIAL_MASK)
        entry[DMK.VARIABLE] = variable
        entry[DMK.ATTRS] = attrs
bekozi commented 7 years ago

Yup, you are correct that this is a bug. The only intent should be to ensure the default attributes are always applied: attrs.update(default_attrs).

bekozi commented 7 years ago

Fixed in master. Thanks, @huard, for finding this.