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

Method _run_axis_tests

numpy/lib/tests/test_arraysetops.py:894–936  ·  view source on GitHub ↗
(self, dtype)

Source from the content-addressed store, hash-verified

892 assert_array_equal(a, b, fmt % dt)
893
894 def _run_axis_tests(self, dtype):
895 data = np.array([[0, 1, 0, 0],
896 [1, 0, 0, 0],
897 [0, 1, 0, 0],
898 [1, 0, 0, 0]]).astype(dtype)
899
900 msg = 'Unique with 1d array and axis=0 failed'
901 result = np.array([0, 1])
902 assert_array_equal(unique(data), result.astype(dtype), msg)
903
904 msg = 'Unique with 2d array and axis=0 failed'
905 result = np.array([[0, 1, 0, 0], [1, 0, 0, 0]])
906 assert_array_equal(unique(data, axis=0), result.astype(dtype), msg)
907
908 msg = 'Unique with 2d array and axis=1 failed'
909 result = np.array([[0, 0, 1], [0, 1, 0], [0, 0, 1], [0, 1, 0]])
910 assert_array_equal(unique(data, axis=1), result.astype(dtype), msg)
911
912 msg = 'Unique with 3d array and axis=2 failed'
913 data3d = np.array([[[1, 1],
914 [1, 0]],
915 [[0, 1],
916 [0, 0]]]).astype(dtype)
917 result = np.take(data3d, [1, 0], axis=2)
918 assert_array_equal(unique(data3d, axis=2), result, msg)
919
920 uniq, idx, inv, cnt = unique(data, axis=0, return_index=True,
921 return_inverse=True, return_counts=True)
922 msg = "Unique's return_index=True failed with axis=0"
923 assert_array_equal(data[idx], uniq, msg)
924 msg = "Unique's return_inverse=True failed with axis=0"
925 assert_array_equal(uniq[inv], data)
926 msg = "Unique's return_counts=True failed with axis=0"
927 assert_array_equal(cnt, np.array([2, 2]), msg)
928
929 uniq, idx, inv, cnt = unique(data, axis=1, return_index=True,
930 return_inverse=True, return_counts=True)
931 msg = "Unique's return_index=True failed with axis=1"
932 assert_array_equal(data[:, idx], uniq)
933 msg = "Unique's return_inverse=True failed with axis=1"
934 assert_array_equal(uniq[:, inv], data)
935 msg = "Unique's return_counts=True failed with axis=1"
936 assert_array_equal(cnt, np.array([2, 1, 1]), msg)
937
938 def test_unique_nanequals(self):
939 # issue 20326

Callers 1

test_unique_axisMethod · 0.95

Calls 4

assert_array_equalFunction · 0.90
uniqueFunction · 0.90
astypeMethod · 0.80
takeMethod · 0.80

Tested by

no test coverage detected