Skip to content

Commit 0550110

Browse files
committed
sort filter values
1 parent 333866b commit 0550110

File tree

1 file changed

+15
-2
lines changed
  • dataset-builder/backend/app/api

1 file changed

+15
-2
lines changed

dataset-builder/backend/app/api/data.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def convert_filter_values(col: str, values: list, df) -> list:
238238
return values
239239

240240
def serialize_values(values: list) -> list:
241-
"""Convert values to JSON-serializable strings."""
241+
"""Convert values to JSON-serializable strings and sort them."""
242242
serialized = []
243243
for val in values:
244244
if val is None:
@@ -247,7 +247,20 @@ def serialize_values(values: list) -> list:
247247
serialized.append("inf" if val > 0 else "-inf")
248248
else:
249249
serialized.append(str(val))
250-
return serialized
250+
251+
# Sort the values - try numeric sort first, fall back to string sort
252+
try:
253+
# Attempt to sort numerically
254+
sorted_vals = sorted(
255+
serialized,
256+
key=lambda x: float(x)
257+
if x not in [None, "inf", "-inf"]
258+
else (float("inf") if x == "inf" else (float("-inf") if x == "-inf" else 0)),
259+
)
260+
return sorted_vals
261+
except (ValueError, TypeError):
262+
# Fall back to string sorting if numeric fails
263+
return sorted(serialized, key=lambda x: (x is None, x))
251264

252265
try:
253266
# For each filter column, compute available options considering only EARLIER filters

0 commit comments

Comments
 (0)