コード例 #1
0
    def when(self, value, then) -> 'SwitchBuilder':
        """Add a value test. If the `base` expression is equal to `value`, then
        returns `then`.

        Warning
        -------
        Missingness always compares to missing. Both ``NA == NA`` and
        ``NA != NA`` return ``NA``. Use :meth:`~SwitchBuilder.when_missing`
        to test missingness.

        Parameters
        ----------
        value : :class:`.Expression`
        then : :class:`.Expression`

        Returns
        -------
        :class:`.SwitchBuilder`
            Mutates and returns `self`.
        """
        can_compare = unify_types(self._base.dtype, value.dtype)
        if not can_compare:
            raise TypeError(
                "cannot compare expressions of type '{}' and '{}'".format(
                    self._base.dtype, value.dtype))

        self._unify_type(then.dtype)
        self._cases.append((value, then))
        return self
コード例 #2
0
ファイル: builders.py プロジェクト: bcajes/hail
    def when(self, value, then) -> 'SwitchBuilder':
        """Add a value test. If the `base` expression is equal to `value`, then
         returns `then`.

        Warning
        -------
        Missingness always compares to missing. Both ``NA == NA`` and
        ``NA != NA`` return ``NA``. Use :meth:`~SwitchBuilder.when_missing`
        to test missingness.

        Parameters
        ----------
        value : :class:`.Expression`
        then : :class:`.Expression`

        Returns
        -------
        :class:`.SwitchBuilder`
            Mutates and returns `self`.
        """
        can_compare = unify_types(self._base.dtype, value.dtype)
        if not can_compare:
            raise TypeError("cannot compare expressions of type '{}' and '{}'".format(
                self._base.dtype, value.dtype))

        self._unify_type(then.dtype)
        self._cases.append((self._base == value, then))
        return self