def testErrorHandling(self): # Test NotImplmentedError that prevents pddarray iteration with self.assertRaises(NotImplementedError): iter(ak.ones(100)) # Test NotImplmentedError that prevents Strings iteration with self.assertRaises(NotImplementedError): iter(ak.array(['String {}'.format(i) for i in range(0, 10)])) # Test ak,histogram against unsupported dtype #with self.assertRaises(ValueError) as cm: # ak.histogram((ak.randint(0, 1, 100, dtype=ak.bool))) #self.assertEqual('Error: histogramMsg: bool not implemented', # cm.exception.args[0]) with self.assertRaises(RuntimeError) as cm: ak.concatenate([ak.array([True]), ak.array([True])]).is_sorted() self.assertEqual('Error: reductionMsg: is_sorted bool not implemented', cm.exception.args[0]) with self.assertRaises(TypeError): ak.ones(100).any([0]) with self.assertRaises(TypeError) as cm: ak.unique(list(range(0, 10))) self.assertEqual('must be pdarray, Strings, or Categorical {}', cm.exception.args[0]) with self.assertRaises(RuntimeError) as cm: ak.concatenate([ak.ones(100), ak.array([True])]) self.assertEqual( 'Error: concatenateMsg: Incompatible arguments: ' + 'Expected float64 dtype but got bool dtype', cm.exception.args[0])
def run_test_unique(strings, test_strings, cat): # unique akuniq = ak.unique(strings) catuniq = ak.unique(cat) akset = set(akuniq.to_ndarray()) catset = set(catuniq.to_ndarray()) assert(akset == catset) # There should be no duplicates assert(akuniq.size == len(akset)) npset = set(np.unique(test_strings)) # When converted to a set, should agree with numpy assert(akset == npset) return akset
def setUp(self): self.maxDiff = None ArkoudaTest.setUp(self) base_words1 = ak.random_strings_uniform(1, 10, UNIQUE, characters='printable') base_words2 = ak.random_strings_lognormal(2, 0.25, UNIQUE, characters='printable') gremlins = np.array(['"', ' ', '']) self.gremlins = ak.array(gremlins) self.base_words = ak.concatenate((base_words1, base_words2)) self.np_base_words = np.hstack( (base_words1.to_ndarray(), base_words2.to_ndarray())) choices = ak.randint(0, self.base_words.size, N) self.strings = self.base_words[choices] self.test_strings = self.strings.to_ndarray() self.cat = ak.Categorical(self.strings) x, w = tuple( zip(*Counter(''.join(self.base_words.to_ndarray())).items())) self.delim = self._get_delimiter(x, w, gremlins) self.akset = set(ak.unique(self.strings).to_ndarray()) self.gremlins_base_words = ak.concatenate( (self.base_words, self.gremlins)) self.gremlins_strings = ak.concatenate( (self.base_words[choices], self.gremlins)) self.gremlins_test_strings = self.gremlins_strings.to_ndarray() self.gremlins_cat = ak.Categorical(self.gremlins_strings)
def test_unused_categories_logic(self): """ Test that Categoricals built from_codes and from slices that have unused categories behave correctly """ s = ak.array([str(i) for i in range(10)]) s12 = s[1:3] cat = ak.Categorical(s) cat12 = cat[1:3] self.assertListEqual( ak.in1d(s, s12).to_ndarray().tolist(), ak.in1d(cat, cat12).to_ndarray().tolist()) self.assertSetEqual(set(ak.unique(s12).to_ndarray().tolist()), set(ak.unique(cat12).to_ndarray().tolist())) cat_from_codes = ak.Categorical.from_codes(ak.array([1, 2]), s) self.assertListEqual( ak.in1d(s, s12).to_ndarray().tolist(), ak.in1d(cat, cat_from_codes).to_ndarray().tolist()) self.assertSetEqual( set(ak.unique(s12).to_ndarray().tolist()), set(ak.unique(cat_from_codes).to_ndarray().tolist()))
def setUp(self): self.maxDiff = None ArkoudaTest.setUp(self) base_words1 = ak.random_strings_uniform(1, 10, UNIQUE, characters='printable') base_words2 = ak.random_strings_lognormal(2, 0.25, UNIQUE, characters='printable') gremlins = ak.array(['"', ' ', '']) self.gremlins = gremlins self.base_words = ak.concatenate((base_words1, base_words2)) self.np_base_words = np.hstack((base_words1.to_ndarray(), base_words2.to_ndarray())) choices = ak.randint(0, self.base_words.size, N) self.strings = self.base_words[choices] self.test_strings = self.strings.to_ndarray() self.cat = ak.Categorical(self.strings) x, w = tuple(zip(*Counter(''.join(self.base_words.to_ndarray())).items())) self.delim = np.random.choice(x, p=(np.array(w)/sum(w))) self.akset = set(ak.unique(self.strings).to_ndarray()) self.gremlins_base_words = base_words = ak.concatenate((base_words1, base_words2, gremlins)) self.gremlins_strings = ak.concatenate((base_words[choices], gremlins)) self.gremlins_test_strings = self.gremlins_strings.to_ndarray() self.gremlins_cat = ak.Categorical(self.gremlins_strings) print("=================In Class will check===========================") print("") print(str(base_words1)) print("After base_word1 ") print("") print(str(self.strings)) print("After Print strings") print(str(self.test_strings)) print("") print("After Print teststrings") print(str(self.strings[N//3])) print("") print("After Print strings[N//3]") print(str(self.test_strings[N//3])) print("") print("After Print test_strings[N//3]")
def test_groupby(self): akset = set(ak.unique(self.strings).to_ndarray()) run_test_groupby(self.strings, self._get_categorical(), akset)