def test_multi_index_type_inferred(self): for index, name in product(_generate_multi_indexes(), test_global_index_names): with self.subTest(index=index): native_index_type = numba.typeof(index) self.assertIsInstance(native_index_type, MultiIndexType) index.name = name with self.subTest(index=index): native_index_type = numba.typeof(index) self.assertIsInstance(native_index_type, MultiIndexType)
def test_multi_index_len(self): def test_impl(index): return len(index) sdc_func = self.jit(test_impl) np.random.seed(0) for index in _generate_multi_indexes(): with self.subTest(index=index): result = sdc_func(index) result_ref = test_impl(index) self.assertEqual(result, result_ref)
def test_multi_index_unbox_and_box(self): def test_impl(index): return index sdc_func = self.jit(test_impl) np.random.seed(0) for index in _generate_multi_indexes(): with self.subTest(index=index): result = sdc_func(index) result_ref = test_impl(index) pd.testing.assert_index_equal(result, result_ref)
def test_multi_index_attribute_values(self): def test_impl(index): return index.values sdc_func = self.jit(test_impl) np.random.seed(0) for index in _generate_multi_indexes(): with self.subTest(index_data=index): result = sdc_func(index) result_ref = test_impl(index) # SDC MultiIndex.values return list but not numpy array self.assertEqual(result, list(result_ref))
def test_multi_index_attribute_names(self): def test_impl(index): return index.names sdc_func = self.jit(test_impl) np.random.seed(0) for index in _generate_multi_indexes(): for names in combinations_with_replacement( test_global_index_names, index.nlevels): index.names = names with self.subTest(index=index): result = sdc_func(index) result_ref = test_impl(index) self.assertEqual(result, result_ref)
def test_multi_index_attribute_codes(self): def test_impl(index): return index.codes sdc_func = self.jit(test_impl) np.random.seed(0) for index in _generate_multi_indexes(): with self.subTest(index_data=index): result = sdc_func(index) result_ref = test_impl(index) # SDC MultiIndex.levels return tuple of levels not list error_msg = f"Indexes'levels are different:\nresult={result},\nresult_ref{result_ref}" self.assertEqual(len(result), len(result_ref), error_msg) self.assertTrue(map( lambda x, y: np.testing.assert_array_equal(x, y), zip(result, result_ref)), error_msg )