Ejemplo n.º 1
0
def _eval_factor(factor_info, data, NA_action):
    factor = factor_info.factor
    result = factor.eval(factor_info.state, data)
    # Returns either a 2d ndarray, or a DataFrame, plus is_NA mask
    if factor_info.type == "numerical":
        result = atleast_2d_column_default(result, preserve_pandas=True)
        _max_allowed_dim(2, result, factor)
        if result.shape[1] != factor_info.num_columns:
            raise PatsyError("when evaluating factor %s, I got %s columns "
                                "instead of the %s I was expecting"
                                % (factor.name(),
                                   factor_info.num_columns,
                                   result.shape[1]),
                                factor)
        if not safe_issubdtype(np.asarray(result).dtype, np.number):
            raise PatsyError("when evaluating numeric factor %s, "
                             "I got non-numeric data of type '%s'"
                             % (factor.name(), result.dtype),
                             factor)
        return result, NA_action.is_numerical_NA(result)
    # returns either a 1d ndarray or a pandas.Series, plus is_NA mask
    else:
        assert factor_info.type == "categorical"
        result = categorical_to_int(result, factor_info.categories, NA_action,
                                    origin=factor_info.factor)
        assert result.ndim == 1
        return result, np.asarray(result == -1)
Ejemplo n.º 2
0
 def eval(self, data, NA_action):
     result = self.factor.eval(self._state, data)
     result = categorical_to_int(result,
                                 self._levels,
                                 NA_action,
                                 origin=self.factor)
     assert result.ndim == 1
     return result, np.asarray(result == -1)
Ejemplo n.º 3
0
 def eval(self, data, NA_action):
     result = self.factor.eval(self._state, data)
     result = categorical_to_int(result, self._levels, NA_action,
                                 origin=self.factor)
     assert result.ndim == 1
     return result, np.asarray(result == -1)