Skip to content

Commit

Permalink
Sort naturally instead of alphabetically on attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperCraeghs committed Sep 25, 2023
1 parent d95f84c commit 54d1ca3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mlx/traceable_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def get_items(self, regex, attributes=None, sortattributes=None, reverse=False,
Args:
regex (str/re.Pattern): Regex pattern or object to match the items in this collection against
attributes (dict): Dictionary with attribute-regex pairs to match the items in this collection against
sortattributes (list): List of attributes on which to alphabetically sort the items
sortattributes (list): List of attributes on which to naturally sort the items
reverse (bool): True for reverse sorting
sort (bool): When sortattributes is falsy: True to enable natural sorting, False to disable sorting
Expand All @@ -313,8 +313,8 @@ def get_items(self, regex, attributes=None, sortattributes=None, reverse=False,
if item.is_match(regex) and (not attributes or item.attributes_match(attributes)):
matches.append(itemid)
if sortattributes:
return sorted(matches, key=lambda itemid: self.get_item(itemid).get_attributes(sortattributes),
reverse=reverse)
return natsorted(matches, key=lambda itemid: self.get_item(itemid).get_attributes(sortattributes),
reverse=reverse)
elif sort:
return natsorted(matches, reverse=reverse)
return matches
Expand Down

0 comments on commit 54d1ca3

Please sign in to comment.