Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
brimoor committed Jul 12, 2022
1 parent 3a9cf87 commit 45b9d61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fiftyone/core/aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ def to_mongo(self, sample_collection):
# Note that we don't need to explicitly handle empty `values` here
# because the `group` stage only outputs a document if there's at least
# one value to compute on!
array = F("values").sort()
array = F("values").sort(numeric=True)
idx = ((F() * array.length()).ceil() - 1).max(0)
quantile_expr = array.let_in(E(self._quantiles).map(array[idx]))

Expand Down
8 changes: 7 additions & 1 deletion fiftyone/core/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2584,7 +2584,7 @@ def reverse(self):
"""
return ViewExpression({"$reverseArray": self})

def sort(self, key=None, reverse=False):
def sort(self, key=None, numeric=False, reverse=False):
"""Sorts this expression, which must resolve to an array.
If no ``key`` is provided, this array must contain elements whose
Expand Down Expand Up @@ -2637,13 +2637,19 @@ def sort(self, key=None, reverse=False):
Args:
key (None): an optional field or ``embedded.field.name`` to sort by
numeric (False): whether the array contains numeric values. By
default, the values will be sorted alphabetically by their
string representations
reverse (False): whether to sort in descending order
Returns:
a :class:`ViewExpression`
"""
if key is not None:
# @todo this implicitly assumes `key` is numeric
comp = "(a, b) => a.{key} - b.{key}".format(key=key)
elif numeric:
comp = "(a, b) => a - b"
else:
comp = ""

Expand Down

0 comments on commit 45b9d61

Please sign in to comment.