Exemplo n.º 1
0
    def test_container_attrs(self) -> None:

        for attr in UFUNC_AXIS_SKIPNA.keys() | UFUNC_SHAPE_SKIPNA.keys():
            c = ContainerOperand
            self.assertTrue(hasattr(c, attr))

        with self.assertRaises(NotImplementedError):
            c().display()
Exemplo n.º 2
0
def get_jinja_contexts() -> tp.Dict[str, tp.List[tp.Tuple[str, str]]]:

    post = {}

    performance_cls = []
    for name in dir(core):
        obj = getattr(core, name)
        if inspect.isclass(obj) and issubclass(obj, PerfTest):
            performance_cls.append(obj.__name__)

    post['performance_cls'] = performance_cls

    def get_func_doc(
            cls: type,
            func_iter: tp.Iterable[str]) -> tp.List[tp.Tuple[str, str]]:
        return [(f, getattr(cls, f).__doc__) for f in sorted(func_iter)]

    for cls in (sf.Index, sf.Series, sf.Frame):
        label = cls.__name__
        post[label + '_operator_unary'] = get_func_doc(cls,
                                                       _UFUNC_UNARY_OPERATORS)
        post[label + '_operator_binary'] = get_func_doc(
            cls, _UFUNC_BINARY_OPERATORS)

    for cls in (sf.Index, sf.Series, sf.Frame):
        label = cls.__name__
        post[label + '_ufunc_axis'] = sorted(UFUNC_AXIS_SKIPNA.keys())

    post['interface'] = []
    for target in (
            sf.Series,
            sf.Frame,
            sf.FrameGO,
            sf.Index,
            sf.IndexGO,
            sf.IndexHierarchy,
            sf.IndexHierarchyGO,
            sf.IndexYear,
            sf.IndexYearGO,
            sf.IndexYearMonth,
            sf.IndexYearMonthGO,
            sf.IndexDate,
            sf.IndexDateGO,
            sf.IndexMinute,
            sf.IndexMinuteGO,
            sf.IndexSecond,
            sf.IndexSecondGO,
            sf.IndexMillisecond,
            sf.IndexMillisecondGO,
            sf.IndexNanosecond,
            sf.IndexNanosecondGO,
    ):
        # import ipdb; ipdb.set_trace()
        post['interface'].append((target.__name__, target.interface))

    return post
Exemplo n.º 3
0
    def test_ufunc_skipna_1d(self, array: np.ndarray) -> None:

        has_na = util.isna_array(array).any()
        for ufunc, ufunc_skipna, dtype in UFUNC_AXIS_SKIPNA.values():

            with np.errstate(over='ignore', under='ignore'):
                v1 = ufunc_skipna(array)
                # this should return a single value
                self.assertFalse(isinstance(v1, np.ndarray))

                if has_na:
                    v2 = ufunc(array)
                    self.assertFalse(isinstance(v2, np.ndarray))
Exemplo n.º 4
0
    def test_ufunc_axis(self, f1: Frame) -> None:

        for attr, attrs in UFUNC_AXIS_SKIPNA.items():

            if attr in ('std', 'var'):
                continue

            for axis in (0, 1):
                values = f1.values
                # must coerce all blocks to same type to compare to what NP does
                # f2 = f1.astype(values.dtype)

                a = getattr(f1, attr)(axis=axis).values # call the method
                b = attrs.ufunc_skipna(values, axis=axis)
Exemplo n.º 5
0
    def test_ufunc_axis_skipna(self, array: np.ndarray) -> None:

        has_na = util.isna_array(array).any()

        for nt in UFUNC_AXIS_SKIPNA.values():
            ufunc = nt.ufunc
            ufunc_skipna = nt.ufunc_skipna
            # dtypes = nt.dtypes
            # composable = nt.composable
            # doc = nt.doc_header
            # size_one_unity = nt.size_one_unity

            with np.errstate(over='ignore', under='ignore', divide='ignore'):

                post = util.ufunc_axis_skipna(array=array,
                                              skipna=True,
                                              axis=0,
                                              ufunc=ufunc,
                                              ufunc_skipna=ufunc_skipna)
                if array.ndim == 2:
                    self.assertTrue(post.ndim == 1)
Exemplo n.º 6
0
 def test_ufunc_axis(self, s1: Series) -> None:
     for attr, attrs in UFUNC_AXIS_SKIPNA.items():
         a = getattr(s1, attr)()
         func = attrs.ufunc_skipna
         b = func(s1.values)
         self.assertEqualWithNaN(a, b)