Skip to content

Commit 8e08be5

Browse files
add test for append with multiple arguments
1 parent 565d42f commit 8e08be5

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

climada/hazard/centroids/centr.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ def append(self, *centr):
344344
345345
Parameters
346346
----------
347-
centr : Centroids
348-
Centroids to append. The centroids need to have the same CRS.
347+
centr : list
348+
List of Centroids to append. The centroids need to have the same CRS.
349349
350350
Raises
351351
------
@@ -366,16 +366,16 @@ def append(self, *centr):
366366

367367
def union(self, *others):
368368
"""Create the union of the current Centroids object with one or more other centroids
369-
objects by passing the list of centroids to `append` for concatenation and then
369+
objects by passing the list of centroids to :py:meth:`append` for concatenation and then
370370
removes duplicates.
371371
372372
All centroids must have the same CRS. Points that are contained in more than one of the
373373
Centroids objects will only be contained once (i.e. duplicates are removed).
374374
375375
Parameters
376376
----------
377-
others : list of Centroids
378-
Centroids contributing to the union.
377+
others : list
378+
List of Centroids contributing to the union.
379379
380380
Returns
381381
-------

climada/hazard/centroids/test/test_centr.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,26 @@ def test_append_dif_crs(self):
816816
with self.assertRaises(ValueError):
817817
self.centr.append(centr2)
818818

819+
def test_append_multiple_arguments(self):
820+
"""Test passing append multiple arguments in the form of a list of Centroids."""
821+
# create a single centroid
822+
lat, lon = np.array([1, 2]), np.array([1, 2])
823+
centr = Centroids(lat=lat, lon=lon)
824+
# create a list of centroids
825+
coords = [(np.array([3, 4]), np.array([3, 4]))]
826+
centroids_list = [Centroids(lat=lat, lon=lon) for lat, lon in coords]
827+
828+
centr.append(*centroids_list)
829+
830+
self.assertEqual(centr.lat[0], 1)
831+
self.assertEqual(centr.lat[1], 2)
832+
self.assertEqual(centr.lat[2], 3)
833+
self.assertEqual(centr.lat[3], 4)
834+
self.assertEqual(centr.lon[0], 1)
835+
self.assertEqual(centr.lon[1], 2)
836+
self.assertEqual(centr.lon[2], 3)
837+
self.assertEqual(centr.lon[3], 4)
838+
819839
def test_remove_duplicate_pass(self):
820840
"""Test remove_duplicate_points"""
821841
centr = Centroids(

0 commit comments

Comments
 (0)