Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
use a class instead of str because Numpy strings are not stable acros…
Browse files Browse the repository at this point in the history
…s versions
  • Loading branch information
jpivarski committed Aug 24, 2018
1 parent 8dfb644 commit c22d507
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tests/test_jagged.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,25 @@ def test_jagged_ufunc(self):
self.assertEqual((numpy.array([100, 200, 300, 400]) + a).tolist(), [[100.0, 101.1, 102.2], [], [303.3, 304.4], [405.5, 406.6, 407.7, 408.8, 409.9]])

def test_jagged_ufunc_object(self):
class Z(object):
def __init__(self, z):
try:
self.z = list(z)
except TypeError:
self.z = z
def __eq__(self, other):
return isinstance(other, Z) and self.z == other.z
def __ne__(self, other):
return not self.__eq__(other)
def __repr__(self):
return "Z({0})".format(self.z)

a = JaggedArray([0, 3, 3, 5], [3, 3, 5, 10], [0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9])
self.assertEqual((awkward.ObjectArray([100, 200, 300, 400], str) + a).tolist(), ["[100. 101.1 102.2]", "[]", "[303.3 304.4]", "[405.5 406.6 407.7 408.8 409.9]"])
self.assertEqual((awkward.ObjectArray([100, 200, 300, 400], Z) + a).tolist(), [Z([100., 101.1, 102.2]), Z([]), Z([303.3, 304.4]), Z([405.5, 406.6, 407.7, 408.8, 409.9])])

a = JaggedArray([0, 3, 3, 5], [3, 3, 5, 10], awkward.ObjectArray([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9], str))
self.assertEqual(a, [["0.0", "1.1", "2.2"], [], ["3.3", "4.4"], ["5.5", "6.6", "7.7", "8.8", "9.9"]])
self.assertEqual(a + awkward.ObjectArray([100, 200, 300, 400], str), [["100.0", "101.1", "102.2"], [], ["303.3", "304.4"], ["405.5", "406.6", "407.7", "408.8", "409.9"]])
a = JaggedArray([0, 3, 3, 5], [3, 3, 5, 10], awkward.ObjectArray([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9], Z))
self.assertEqual(a, [[Z(0.0), Z(1.1), Z(2.2)], [], [Z(3.3), Z(4.4)], [Z(5.5), Z(6.6), Z(7.7), Z(8.8), Z(9.9)]])
self.assertEqual(a + awkward.ObjectArray([100, 200, 300, 400], Z), [[Z(100.0), Z(101.1), Z(102.2)], [], [Z(303.3), Z(304.4)], [Z(405.5), Z(406.6), Z(407.7), Z(408.8), Z(409.9)]])

def test_jagged_ufunc_table(self):
a = JaggedArray([0, 3, 3, 5], [3, 3, 5, 10], [0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9])
Expand Down

0 comments on commit c22d507

Please sign in to comment.