def test_int64_index_type_inferred(self): for data in _generate_valid_int64_index_data(): for name in test_global_index_names: index = pd.Int64Index(data, name=name) with self.subTest(index=index): native_index_type = numba.typeof(index) self.assertIsInstance(native_index_type, Int64IndexType)
def test_int64_index_create_and_box(self): def test_impl(data, name): return pd.Int64Index(data, name=name) sdc_func = self.jit(test_impl) name = 'index' for data in _generate_valid_int64_index_data(): with self.subTest(index_data=data): result = sdc_func(data, name) result_ref = test_impl(data, name) pd.testing.assert_index_equal(result, result_ref)
def test_int64_index_attribute_values(self): def test_impl(index): return index.values sdc_func = self.jit(test_impl) for data in _generate_valid_int64_index_data(): index = pd.Int64Index(data) with self.subTest(index_data=data): result = sdc_func(index) result_ref = test_impl(index) np.testing.assert_array_equal(result, result_ref)
def test_int64_index_copy(self): def test_impl(index, new_name): return index.copy(name=new_name) sdc_func = self.jit(test_impl) for data in _generate_valid_int64_index_data(): for name, new_name in product(test_global_index_names, repeat=2): index = pd.Int64Index(data, name=name) with self.subTest(index=index, new_name=new_name): result = sdc_func(index, new_name) result_ref = test_impl(index, new_name) pd.testing.assert_index_equal(result, result_ref)
def test_int64_index_support_copy(self): from sdc.functions.numpy_like import copy @self.jit def sdc_func(index): return copy(index) for data in _generate_valid_int64_index_data(): for name in test_global_index_names: index = pd.Int64Index(data, name=name) with self.subTest(index=index): result = sdc_func(index) pd.testing.assert_index_equal(result, index)
def test_int64_index_getitem_scalar(self): def test_impl(index, idx): return index[idx] sdc_func = self.jit(test_impl) for data in _generate_valid_int64_index_data(): index = pd.Int64Index(data) n = len(index) values_to_test = [-n, n // 2, n - 1] for idx in values_to_test: with self.subTest(index=index, idx=idx): result = sdc_func(index, idx) result_ref = test_impl(index, idx) self.assertEqual(result, result_ref)
def test_int64_index_getitem_slice(self): def test_impl(index, idx): return index[idx] sdc_func = self.jit(test_impl) n = 17 slices_params = combinations_with_replacement( [None, 0, -1, n // 2, n, n - 3, n + 3, -(n + 3)], 2) for data in _generate_valid_int64_index_data(): index = pd.Int64Index(data, name='abc') for slice_start, slice_stop in slices_params: for slice_step in [1, -1, 2]: idx = slice(slice_start, slice_stop, slice_step) with self.subTest(index=index, idx=idx): result = sdc_func(index, idx) result_ref = test_impl(index, idx) pd.testing.assert_index_equal(result, result_ref)
def test_int64_index_getitem_slice(self): def test_impl(index, idx): return index[idx] sdc_func = self.jit(test_impl) index_len = 11 slices_params = combinations_with_replacement( [None, 0, -1, index_len // 2, index_len, index_len - 3, index_len + 3, -(index_len + 3)], 3 ) for data in _generate_valid_int64_index_data(): for slice_start, slice_stop, slice_step in slices_params: # slice step cannot be zero if slice_step == 0: continue idx = slice(slice_start, slice_stop, slice_step) index = pd.Int64Index(data, name='abc') with self.subTest(index=index, idx=idx): result = sdc_func(index, idx) result_ref = test_impl(index, idx) pd.testing.assert_index_equal(result, result_ref)