def testConcatenate(self): catOne = self._getCategorical() catTwo = self._getRandomizedCategorical() resultCat = catOne.concatenate([catTwo]) self.assertEqual('category', resultCat.objtype) self.assertIsInstance(resultCat, ak.Categorical) self.assertEqual(20, resultCat.size) # Since Categorical.concatenate uses Categorical.from_codes method, confirm # that both permutation and segments are None self.assertFalse(resultCat.permutation) self.assertFalse(resultCat.segments) resultCat = ak.concatenate([catOne, catOne]) self.assertEqual('category', resultCat.objtype) self.assertIsInstance(resultCat, ak.Categorical) self.assertEqual(20, resultCat.size) # Since Categorical.concatenate uses Categorical.from_codes method, confirm # that both permutation and segments are None self.assertFalse(resultCat.permutation) self.assertFalse(resultCat.segments) resultCat = ak.concatenate([catOne, catOne], ordered=False) self.assertEqual('category', resultCat.objtype) self.assertIsInstance(resultCat, ak.Categorical) self.assertEqual(20, resultCat.size) # Since Categorical.concatenate uses Categorical.from_codes method, confirm # that both permutation and segments are None self.assertFalse(resultCat.permutation) self.assertFalse(resultCat.segments)
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 testConcatenate(self): pdaOne = ak.arange(1, 4) pdaTwo = ak.arange(4, 7) self.assertTrue((ak.array([1, 2, 3, 4, 5, 6]) == ak.concatenate([pdaOne, pdaTwo])).all()) self.assertTrue((ak.array([4, 5, 6, 1, 2, 3]) == ak.concatenate([pdaTwo, pdaOne])).all()) pdaOne = ak.linspace(start=1, stop=3, length=3) pdaTwo = ak.linspace(start=4, stop=6, length=3) self.assertTrue((ak.array([1, 2, 3, 4, 5, 6]) == ak.concatenate([pdaOne, pdaTwo])).all()) self.assertTrue((ak.array([4, 5, 6, 1, 2, 3]) == ak.concatenate([pdaTwo, pdaOne])).all()) pdaOne = ak.array([True, False, True]) pdaTwo = ak.array([False, True, True]) self.assertTrue((ak.array([True, False, True, False, True, True]) == ak.concatenate([pdaOne, pdaTwo])).all())
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 _get_ak_gremlins(self): gremlins_base_words = ak.concatenate((self.base_words, self.gremlins)) gremlins_strings = ak.concatenate( (self.base_words[self.choices], self.gremlins)) gremlins_test_strings = gremlins_strings.to_ndarray() gremlins_cat = ak.Categorical(gremlins_strings) return self.Gremlins(gremlins_base_words, gremlins_strings, gremlins_test_strings, gremlins_cat)
def test_error_handling(self): 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]) with self.assertRaises(TypeError): ak.union1d([-1, 0, 1], [-2, 0, 2]) with self.assertRaises(RuntimeError) as cm: ak.cos(ak.randint(0, 1, 100, dtype=ak.bool)) self.assertEqual('Error: efuncMsg: cos bool not implemented', cm.exception.args[0])
def testPdArrayConcatenation(self): onesOne = ak.randint(0, 100, 100) onesTwo = ak.randint(0, 100, 100) result = ak.concatenate([onesOne, onesTwo]) self.assertEqual(200, len(result)) self.assertEqual(np.int64, result.dtype)
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): ak.histogram((ak.randint(0, 1, 100, dtype=ak.bool))) 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])
def test_concatenate(self): s1 = self._get_strings('string',51) s2 = self._get_strings('string-two', 51) resultStrings = ak.concatenate([s1,s2]) self.assertIsInstance(resultStrings, ak.Strings) self.assertEqual(100,resultStrings.size) resultStrings = ak.concatenate([s1,s1], ordered=False) self.assertIsInstance(resultStrings, ak.Strings) self.assertEqual(100,resultStrings.size) s1 = self._get_strings('string',6) s2 = self._get_strings('string-two', 6) expectedResult = ak.array(['string 1', 'string 2', 'string 3', 'string 4', 'string 5', 'string-two 1', 'string-two 2', 'string-two 3', 'string-two 4', 'string-two 5']) # Ordered concatenation s12ord = ak.concatenate([s1, s2], ordered=True) self.assertTrue((expectedResult == s12ord).all())
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 setUp(self): ArkoudaTest.setUp(self) base_words1 = ak.random_strings_uniform(0, 10, UNIQUE, characters='printable') base_words2 = ak.random_strings_lognormal(2, 0.25, UNIQUE, characters='printable') 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)).items())) self.delim = np.random.choice(x, p=(np.array(w) / sum(w)))
def testConcatenate(self): catOne = self._getCategorical('string', 51) catTwo = self._getCategorical('string-two', 51) resultCat = catOne.concatenate([catTwo]) self.assertEqual('category', resultCat.objtype) self.assertIsInstance(resultCat, ak.Categorical) self.assertEqual(100, resultCat.size) # Since Categorical.concatenate uses Categorical.from_codes method, confirm # that both permutation and segments are None self.assertFalse(resultCat.permutation) self.assertFalse(resultCat.segments) resultCat = ak.concatenate([catOne, catOne], ordered=False) self.assertEqual('category', resultCat.objtype) self.assertIsInstance(resultCat, ak.Categorical) self.assertEqual(100, resultCat.size) # Since Categorical.concatenate uses Categorical.from_codes method, confirm # that both permutation and segments are None self.assertFalse(resultCat.permutation) self.assertFalse(resultCat.segments) # Concatenate two Categoricals with different categories, and test result against original strings s1 = ak.array(['abc', 'de', 'abc', 'fghi', 'de']) s2 = ak.array(['jkl', 'mno', 'fghi', 'abc', 'fghi', 'mno']) c1 = ak.Categorical(s1) c2 = ak.Categorical(s2) # Ordered concatenation s12ord = ak.concatenate([s1, s2], ordered=True) c12ord = ak.concatenate([c1, c2], ordered=True) self.assertTrue((ak.Categorical(s12ord) == c12ord).all()) # Unordered (but still deterministic) concatenation s12unord = ak.concatenate([s1, s2], ordered=False) c12unord = ak.concatenate([c1, c2], ordered=False) self.assertTrue((ak.Categorical(s12unord) == c12unord).all()) # Tiny concatenation # Used to fail when length of array was less than numLocales # CI uses 2 locales, so try with length-1 arrays a = ak.Categorical(ak.array(['a'])) b = ak.Categorical(ak.array(['b'])) c = ak.concatenate((a, b), ordered=False) ans = ak.Categorical(ak.array(['a', 'b'])) self.assertTrue((c == ans).all())
import sys if len(sys.argv) > 1: ak.connect(server=sys.argv[1], port=sys.argv[2]) else: ak.connect() print("Running test from string_test.__main__") # with open(__file__, 'r') as f: # base_words = np.array(f.read().split()) # test_strings = np.random.choice(base_words, N, replace=True) # strings = ak.array(test_strings) 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(['"', ' ', '']) base_words = ak.concatenate((base_words1, base_words2)) np_base_words = np.hstack((base_words1.to_ndarray(), base_words2.to_ndarray())) assert(compare_strings(base_words.to_ndarray(), np_base_words)) choices = ak.randint(0, base_words.size, N) strings = base_words[choices] test_strings = strings.to_ndarray() cat = ak.Categorical(strings) print("strings =", strings) print("categorical =", cat) print("Generation and concatenate passed") # int index run_test_index(strings, test_strings, cat, range(-len(gremlins), 0)) print("int index passed") # slice
# with open(__file__, 'r') as f: # base_words = np.array(f.read().split()) # test_strings = np.random.choice(base_words, N, replace=True) # strings = ak.array(test_strings) 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([' ', '']) base_words = ak.concatenate((base_words1, base_words2, gremlins)) np_base_words = np.hstack( (base_words1.to_ndarray(), base_words2.to_ndarray())) assert (compare_strings(base_words.to_ndarray(), np_base_words)) choices = ak.randint(0, base_words.size, N) strings = ak.concatenate((base_words[choices], gremlins)) test_strings = strings.to_ndarray() cat = ak.Categorical(strings) print("strings =", strings) print("categorical =", cat) print("Generation and concatenate passed") # int index run_test_index(strings, test_strings, cat) print("int index passed")