Esempio n. 1
0
 def __getitem__(self, i: int) -> typing.Union[typing.Optional[bool],
                                               'BoolSexpVector']:
     cdata = self.__sexp__._cdata
     if isinstance(i, int):
         i_c = _rinterface._python_index_to_c(cdata, i)
         elt = openrlib.LOGICAL_ELT(cdata, i_c)
         res = na_values.NA_Logical if elt == NA_Logical else bool(elt)
     elif isinstance(i, slice):
         res = type(self).from_iterable(
             [openrlib.LOGICAL_ELT(cdata, i_c)
              for i_c in range(*i.indices(len(self)))]
         )
     else:
         raise TypeError(
             'Indices must be integers or slices, not %s' % type(i))
     return res
Esempio n. 2
0
 def __getitem__(
     self, i: Union[int, slice]
 ) -> Union[bool, 'sexp.NALogicalType', 'BoolSexpVector']:
     res: Union[bool, 'sexp.NALogicalType', 'BoolSexpVector']
     cdata = self.__sexp__._cdata
     if isinstance(i, int):
         i_c = _rinterface._python_index_to_c(cdata, i)
         elt = openrlib.LOGICAL_ELT(cdata, i_c)
         res = (
             na_values.NA_Logical  # type: ignore
             if elt == NA_Logical else bool(elt))
     elif isinstance(i, slice):
         res = type(self).from_iterable([
             openrlib.LOGICAL_ELT(cdata, i_c)
             for i_c in range(*i.indices(len(self)))
         ])
     else:
         raise TypeError('Indices must be integers or slices, not %s' %
                         type(i))
     return res
Esempio n. 3
0
def test_get_logical_elt_fallback():
    rpy2.rinterface.initr()
    v = rpy2.rinterface.BoolSexpVector([True, True, False])
    assert (openrlib.LOGICAL_ELT(v.__sexp__._cdata, 1) \
            == \
            openrlib._get_logical_elt_fallback(v.__sexp__._cdata, 1))