MCPcopy
hub / github.com/numpy/numpy / test_unique_array_api_functions

Method test_unique_array_api_functions

numpy/lib/tests/test_arraysetops.py:1208–1249  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1206 assert_array_equal(not_unq, np.array([1, np.nan, np.nan, np.nan]))
1207
1208 def test_unique_array_api_functions(self):
1209 arr = np.array(
1210 [
1211 np.nan, 1.0, 0.0, 4.0, -np.nan,
1212 -0.0, 1.0, 3.0, 4.0, np.nan,
1213 5.0, -0.0, 1.0, -np.nan, 0.0,
1214 ],
1215 )
1216
1217 for res_unique_array_api, res_unique in [
1218 (
1219 np.unique_values(arr),
1220 np.unique(arr, equal_nan=False)
1221 ),
1222 (
1223 np.unique_counts(arr),
1224 np.unique(arr, return_counts=True, equal_nan=False)
1225 ),
1226 (
1227 np.unique_inverse(arr),
1228 np.unique(arr, return_inverse=True, equal_nan=False)
1229 ),
1230 (
1231 np.unique_all(arr),
1232 np.unique(
1233 arr,
1234 return_index=True,
1235 return_inverse=True,
1236 return_counts=True,
1237 equal_nan=False
1238 )
1239 )
1240 ]:
1241 assert len(res_unique_array_api) == len(res_unique)
1242 if not isinstance(res_unique_array_api, tuple):
1243 res_unique_array_api = (res_unique_array_api,)
1244 if not isinstance(res_unique, tuple):
1245 res_unique = (res_unique,)
1246
1247 for actual, expected in zip(res_unique_array_api, res_unique):
1248 # Order of output is not guaranteed
1249 assert_equal(np.sort(actual), np.sort(expected))
1250
1251 def test_unique_inverse_shape(self):
1252 # Regression test for https://github.com/numpy/numpy/issues/25552

Callers

nothing calls this directly

Calls 2

assert_equalFunction · 0.90
sortMethod · 0.45

Tested by

no test coverage detected