Example #1
0
    def test_indexes_index_get_df_index(self):
        def test_impl(df):
            return df.index

        sdc_func = self.jit(test_impl)

        n = 11
        for index in _generate_index_param_values(n):
            with self.subTest(df_index=index):
                df = pd.DataFrame({'A': np.ones(n)}, index=index)
                result = sdc_func(df)
                result_ref = test_impl(df)
                self.assert_indexes_equal(result, result_ref)
Example #2
0
    def test_indexes_index_create_df_with_index(self):
        @self.jit
        def test_impl(A, B, index):
            df = pd.DataFrame({'A': A, 'B': B}, index=index)
            return df.index

        n = 11
        A, B = np.ones(n), np.arange(n)
        for index in _generate_index_param_values(n):
            expected_res = pd.RangeIndex(n) if index is None else index
            with self.subTest(df_index=index):
                result = test_impl(A, B, index)
                self.assert_indexes_equal(result, expected_res)
Example #3
0
    def test_indexes_index_box_df_with_index(self):
        def test_impl(A, B, index):
            return pd.DataFrame({'A': A, 'B': B}, index=index)

        sdc_func = self.jit(test_impl)

        n = 11
        A, B = np.ones(n), np.arange(n, dtype=np.intp)
        for index in _generate_index_param_values(n):
            with self.subTest(df_index=index):
                result = sdc_func(A, B, index)
                result_ref = test_impl(A, B, index)
                pd.testing.assert_frame_equal(result, result_ref)
Example #4
0
    def test_indexes_index_get_series_index(self):
        def test_impl(S):
            return S.index

        sdc_func = self.jit(test_impl)

        n = 11
        for index in _generate_index_param_values(n):
            with self.subTest(series_index=index):
                S = pd.Series(np.ones(n), index=index)
                result = sdc_func(S)
                result_ref = test_impl(S)
                self.assert_indexes_equal(result, result_ref)
Example #5
0
    def test_indexes_box_series_with_index(self):
        def test_impl(data, index):
            return pd.Series(data=data, index=index)

        sdc_func = self.jit(test_impl)

        n = 11
        series_data = np.ones(n)
        for index in _generate_index_param_values(n):
            with self.subTest(series_index=index):
                result = sdc_func(series_data, index)
                result_ref = test_impl(series_data, index)
                pd.testing.assert_series_equal(result, result_ref)
Example #6
0
    def test_indexes_create_series_with_index(self):
        @self.jit
        def test_impl(data, index):
            S = pd.Series(data=data, index=index)
            return S.index

        n = 11
        series_data = np.ones(n)
        for index in _generate_index_param_values(n):
            expected_res = pd.RangeIndex(n) if index is None else index
            with self.subTest(series_index=index):
                result = test_impl(series_data, index)
                self.assert_indexes_equal(result, expected_res)
Example #7
0
    def test_indexes_unbox_series_with_index(self):
        @self.jit
        def test_impl(S):
            # TO-DO: this actually includes calling 'index' attribute overload, should really be S._index,
            # but this requires separate type (e.g. DefaultIndexType) instead of types.none as default index
            return S.index

        n = 11
        for index in _generate_index_param_values(n):
            expected_res = pd.RangeIndex(n) if index is None else index
            with self.subTest(series_index=index):
                S = pd.Series(np.ones(n), index=index)
                result = test_impl(S)
                self.assert_indexes_equal(result, expected_res)
Example #8
0
    def test_indexes_unbox_df_with_index(self):
        @self.jit
        def test_impl(df):
            # TO-DO: this actually includes calling 'index' attribute overload, should really be df._index,
            # but this requires separate type (e.g. PositionalIndexType) instead of types.none as default index
            return df.index

        n = 11
        for index in _generate_index_param_values(n):
            expected_res = pd.RangeIndex(n) if index is None else index
            with self.subTest(df_index=index):
                df = pd.DataFrame({
                    'A': np.ones(n),
                    'B': np.arange(n)
                },
                                  index=index)
                result = test_impl(df)
                self.assert_indexes_equal(result, expected_res)