Skip to content

Commit 7d60412

Browse files
committed
fix: solve confusion between parts and size by setting a non squared example
1 parent aaaa433 commit 7d60412

6 files changed

+14
-273
lines changed

geetools/ee_list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ def chunked(self, parts: int | ee.Number) -> ee.List:
319319
idxList = ee.List.sequence(0, parts.subtract(1))
320320

321321
def compute_parts(idx: ee.Number) -> ee.List:
322-
start = ee.Number(idx).multiply(parts)
322+
start = ee.Number(idx).multiply(size)
323323
return self._obj.slice(start, start.add(size))
324324

325325
chunked = ee.List(idxList.map(compute_parts))
326326

327327
# add the rest of the elements (the rest of the euclidean division)
328328
# to the last chunk of the list.
329-
rest = self._obj.slice(totalSize.subtract(totalSize.mod(size)), totalSize)
329+
rest = self._obj.slice(totalSize.subtract(totalSize.mod(parts)), totalSize)
330330
lastChunk = ee.List(chunked.get(-1)).cat(rest)
331331

332332
return chunked.set(-1, lastChunk)

tests/test_List.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ class TestChunked:
120120
"""Test the chunked method."""
121121

122122
def test_chunked_even(self, ee_list_regression):
123-
input = ee.List([1, 2, 3, 4, 5, 6, 7, 8, 9])
124-
chunked = input.geetools.chunked(3)
125-
# should return -> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
123+
input = ee.List([1, 2, 3, 4, 5, 6, 7, 8])
124+
chunked = input.geetools.chunked(4)
125+
# should return -> [[1, 2], [3, 4], [5, 6], [7, 8]]
126126
ee_list_regression.check(chunked)
127127

128128
def test_chunked_odd(self, ee_list_regression):
129-
input = ee.List([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
130-
chunked = input.geetools.chunked(3)
131-
# should return -> [[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]
129+
input = ee.List([1, 2, 3, 4, 5, 6, 7, 8, 9])
130+
chunked = input.geetools.chunked(4)
131+
# should return -> [[1, 2], [3, 4], [5, 6], [7, 8, 9]]
132132
ee_list_regression.check(chunked)

tests/test_List/serialized_test_chunked_even.yml

-128
This file was deleted.

tests/test_List/serialized_test_chunked_odd.yml

-129
This file was deleted.

tests/test_List/test_chunked_even.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
- - 1
22
- 2
3-
- 3
4-
- - 4
5-
- 5
3+
- - 3
4+
- 4
5+
- - 5
66
- 6
77
- - 7
88
- 8
9-
- 9

tests/test_List/test_chunked_odd.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
- - 1
22
- 2
3-
- 3
4-
- - 4
5-
- 5
3+
- - 3
4+
- 4
5+
- - 5
66
- 6
77
- - 7
88
- 8
99
- 9
10-
- 10

0 commit comments

Comments
 (0)