Exemplo n.º 1
0
    def any_of(self, *states, **kwargs):
        '''
        Return a boolean array containing True where the value of the
        MappedArray equals any state in states.

        :param states: List of states.
        :type states: [str]
        :param ignore_missing: If this is False, raise an exception if any of
            the states are not in the values mapping.
        :type ignore_missing: bool
        :returns: Boolean array.
        :rtype: np.ma.array(bool)
        '''
        ignore_missing = kwargs.get('ignore_missing', False)
        raw_values = []
        for state in states:
            if state not in self.state:
                if ignore_missing:
                    # do not check array as invalid states cause
                    # exception level log messages.
                    continue
                else:
                    raise ValueError(
                        "State '%s' is not valid. Valid states: '%s'." %
                        (state, self.state.keys()))
            raw_values.extend(self.state[state])
        return MaskedArray(in1d(self.raw.data, raw_values), mask=self.mask)
    def any_of(self, *states, **kwargs):
        '''
        Return a boolean array containing True where the value of the
        MappedArray equals any state in states.

        :param states: List of states.
        :type states: [str]
        :param ignore_missing: If this is False, raise an exception if any of
            the states are not in the values mapping.
        :type ignore_missing: bool
        :returns: Boolean array.
        :rtype: np.ma.array(bool)
        '''
        ignore_missing = kwargs.get('ignore_missing', False)
        raw_values = []
        for state in states:
            if state not in self.state:
                if ignore_missing:
                    # do not check array as invalid states cause
                    # exception level log messages.
                    continue
                else:
                    raise ValueError(
                        "State '%s' is not valid. Valid states: '%s'." %
                        (state, self.state.keys()))
            raw_values.extend(self.state[state])
        return MaskedArray(in1d(self.raw.data, raw_values), mask=self.mask)
 def __equality__(self, other, invert=False):
     '''
     Test equality or inequality allowing for multiple raw values matching a
     state.
     '''
     raw_values = self.__raw_values__(other)
     if raw_values:
         return MaskedArray(in1d(self.raw.data, raw_values, invert=invert), mask=self.mask)
     else:
         method = MaskedArray.__ne__ if invert else MaskedArray.__eq__
         return method(self.raw, self.__coerce_type(other))
Exemplo n.º 4
0
 def __equality__(self, other, invert=False):
     '''
     Test equality or inequality allowing for multiple raw values matching a
     state.
     '''
     raw_values = self.__raw_values__(other)
     if raw_values:
         return MaskedArray(in1d(self.raw.data, raw_values, invert=invert),
                            mask=self.mask)
     else:
         method = MaskedArray.__ne__ if invert else MaskedArray.__eq__
         return method(self.raw, self.__coerce_type(other))