-
Notifications
You must be signed in to change notification settings - Fork 125
refactor: Better sort #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the sortMany
method in the ImageCollection class to use a simpler chaining approach with Google Earth Engine's native sort functionality instead of a custom bubble sort implementation using computed indices.
- Replaces complex position computation logic with iterative chaining of GEE's native sort operations
- Adds validation to ensure properties and ascending arrays are the same size
- Simplifies the implementation while maintaining the same functionality for multi-property sorting
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
geetools/ee_image_collection.py |
Main implementation change - refactored sortMany method to use chained sorting |
tests/test_ImageCollection.py |
Updated test to validate error handling for mismatched array sizes |
Multiple serialized test files | Updated expected outputs reflecting the new implementation structure |
Comments suppressed due to low confidence (1)
tests/test_ImageCollection.py:525
- The test only validates one specific error case (mismatched array sizes), but doesn't test the actual sorting functionality with the new implementation. Consider adding a test that verifies the sorting behavior still works correctly.
with pytest.raises(ValueError):
I made some tests to benchmark this new solution agains the previous one using the following code: import ee
import geetools
import pandas as pd
ee.Initialize(project="ee-geetools")
with ee.geetools.Profiler() as p:
ic = ee.ImageCollection("NOAA/GFS0P25")
icSorted = (
ic.limit(500)
.geetools.sortMany(["forecast_time", "creation_time"])
.limit(30)
)
info = icSorted.toList(icSorted.size()).map(lambda x: ee.Dictionary({
"index": ee.Image(x).get("system:index"),
"forecast_time": ee.Date(ee.Image(x).get("forecast_time")).format(),
"creation_time": ee.Date(ee.Image(x).get("creation_time")).format()
})).getInfo()
df = pd.DataFrame(p.profile)
df["EECU-s"].sum() they are in competing range:
So I guess we are not making computation explode with this modifications. |
This PR simply changes the implementation of the sorting algorithm. Chaining sort algo is possible in GEE and I guess it's not less performant than running our own bubble sort using computed indices. The only trick is to run through the properties in reverse order as the last one to run has priority over the others.
I didn't do performances checks yet but my guess is that it's equivalent. readability being much easier.