Skip to content

Commit 32a6b2f

Browse files
committed
sorting functions
1 parent eeaa4f1 commit 32a6b2f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/pint_array/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,22 @@ def matrix_transpose(x):
556556

557557
mod.matrix_transpose = matrix_transpose
558558

559+
## Sorting Functions ##
560+
def get_sort_fun(func_str):
561+
def sort_fun(x, /, **kwargs):
562+
x = asarray(x)
563+
magnitude = xp.asarray(x.magnitude, copy=True)
564+
xp_func = getattr(xp, func_str)
565+
magnitude = xp_func(magnitude, **kwargs)
566+
units = x.units if func_str == "sort" else None
567+
return ArrayUnitQuantity(magnitude, units)
568+
569+
return sort_fun
570+
571+
sort_names = ["sort", "argsort"]
572+
for name in sort_names:
573+
setattr(mod, name, get_sort_fun(name))
574+
559575
## Set Functions ##
560576
def get_set_fun(func_str):
561577
def set_fun(x, /):

0 commit comments

Comments
 (0)