MCPcopy Create free account
hub / github.com/numpy/numpy / test_string_comparisons

Function test_string_comparisons

numpy/core/tests/test_strings.py:50–72  ·  view source on GitHub ↗
(op, ufunc, sym, dtypes, aligned)

Source from the content-addressed store, hash-verified

48 ("<U1", "<U10"), ("<U1", ">U10")])
49@pytest.mark.parametrize("aligned", [True, False])
50def test_string_comparisons(op, ufunc, sym, dtypes, aligned):
51 # ensure native byte-order for the first view to stay within unicode range
52 native_dt = np.dtype(dtypes[0]).newbyteorder("=")
53 arr = np.arange(2**15).view(native_dt).astype(dtypes[0])
54 if not aligned:
55 # Make `arr` unaligned:
56 new = np.zeros(arr.nbytes + 1, dtype=np.uint8)[1:].view(dtypes[0])
57 new[...] = arr
58 arr = new
59
60 arr2 = arr.astype(dtypes[1], copy=True)
61 np.random.shuffle(arr2)
62 arr[0] = arr2[0] # make sure one matches
63
64 expected = [op(d1, d2) for d1, d2 in zip(arr.tolist(), arr2.tolist())]
65 assert_array_equal(op(arr, arr2), expected)
66 assert_array_equal(ufunc(arr, arr2), expected)
67 assert_array_equal(np.compare_chararrays(arr, arr2, sym, False), expected)
68
69 expected = [op(d2, d1) for d1, d2 in zip(arr.tolist(), arr2.tolist())]
70 assert_array_equal(op(arr2, arr), expected)
71 assert_array_equal(ufunc(arr2, arr), expected)
72 assert_array_equal(np.compare_chararrays(arr2, arr, sym, False), expected)
73
74
75@pytest.mark.parametrize(["op", "ufunc", "sym"], COMPARISONS)

Callers

nothing calls this directly

Calls 6

assert_array_equalFunction · 0.90
ufuncClass · 0.85
astypeMethod · 0.80
dtypeMethod · 0.45
viewMethod · 0.45
tolistMethod · 0.45

Tested by

no test coverage detected