Merged
Conversation
There was a problem hiding this comment.
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):
Member
Author
|
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.