@@ -186,7 +186,9 @@ def unique(ar, return_index=False, return_inverse=False,
186
186
.. versionadded:: 1.24
187
187
188
188
sorted : bool, optional
189
- If True, the unique elements are sorted.
189
+ If True, the unique elements are sorted. Elements may be sorted in
190
+ practice even if ``sorted=False``, but this could change without
191
+ notice.
190
192
191
193
.. versionadded:: 2.3
192
194
@@ -361,12 +363,6 @@ def _unique1d(ar, return_index=False, return_inverse=False,
361
363
362
364
optional_indices = return_index or return_inverse
363
365
364
- if (optional_indices or return_counts ) and not sorted :
365
- raise ValueError (
366
- "Currently, `sorted` can only be False if `return_index`, "
367
- "`return_inverse`, and `return_counts` are all False."
368
- )
369
-
370
366
# masked arrays are not supported yet.
371
367
if not optional_indices and not return_counts and not np .ma .is_masked (ar ):
372
368
# First we convert the array to a numpy array, later we wrap it back
@@ -448,10 +444,14 @@ def unique_all(x):
448
444
This function is an Array API compatible alternative to::
449
445
450
446
np.unique(x, return_index=True, return_inverse=True,
451
- return_counts=True, equal_nan=False)
447
+ return_counts=True, equal_nan=False, sorted=False )
452
448
453
449
but returns a namedtuple for easier access to each output.
454
450
451
+ .. note::
452
+ This function currently always returns a sorted result, however,
453
+ this could change in any NumPy minor release.
454
+
455
455
Parameters
456
456
----------
457
457
x : array_like
@@ -507,10 +507,14 @@ def unique_counts(x):
507
507
508
508
This function is an Array API compatible alternative to::
509
509
510
- np.unique(x, return_counts=True, equal_nan=False)
510
+ np.unique(x, return_counts=True, equal_nan=False, sorted=False )
511
511
512
512
but returns a namedtuple for easier access to each output.
513
513
514
+ .. note::
515
+ This function currently always returns a sorted result, however,
516
+ this could change in any NumPy minor release.
517
+
514
518
Parameters
515
519
----------
516
520
x : array_like
@@ -559,10 +563,14 @@ def unique_inverse(x):
559
563
560
564
This function is an Array API compatible alternative to::
561
565
562
- np.unique(x, return_inverse=True, equal_nan=False)
566
+ np.unique(x, return_inverse=True, equal_nan=False, sorted=False )
563
567
564
568
but returns a namedtuple for easier access to each output.
565
569
570
+ .. note::
571
+ This function currently always returns a sorted result, however,
572
+ this could change in any NumPy minor release.
573
+
566
574
Parameters
567
575
----------
568
576
x : array_like
0 commit comments