Skip to content

Commit

Permalink
add test for append with multiple arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasColombi committed Dec 20, 2024
1 parent 565d42f commit 8e08be5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
10 changes: 5 additions & 5 deletions climada/hazard/centroids/centr.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ def append(self, *centr):
Parameters
----------
centr : Centroids
Centroids to append. The centroids need to have the same CRS.
centr : list
List of Centroids to append. The centroids need to have the same CRS.
Raises
------
Expand All @@ -366,16 +366,16 @@ def append(self, *centr):

def union(self, *others):
"""Create the union of the current Centroids object with one or more other centroids
objects by passing the list of centroids to `append` for concatenation and then
objects by passing the list of centroids to :py:meth:`append` for concatenation and then
removes duplicates.
All centroids must have the same CRS. Points that are contained in more than one of the
Centroids objects will only be contained once (i.e. duplicates are removed).
Parameters
----------
others : list of Centroids
Centroids contributing to the union.
others : list
List of Centroids contributing to the union.
Returns
-------
Expand Down
20 changes: 20 additions & 0 deletions climada/hazard/centroids/test/test_centr.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,26 @@ def test_append_dif_crs(self):
with self.assertRaises(ValueError):
self.centr.append(centr2)

def test_append_multiple_arguments(self):
"""Test passing append multiple arguments in the form of a list of Centroids."""
# create a single centroid
lat, lon = np.array([1, 2]), np.array([1, 2])
centr = Centroids(lat=lat, lon=lon)
# create a list of centroids
coords = [(np.array([3, 4]), np.array([3, 4]))]
centroids_list = [Centroids(lat=lat, lon=lon) for lat, lon in coords]

centr.append(*centroids_list)

self.assertEqual(centr.lat[0], 1)
self.assertEqual(centr.lat[1], 2)
self.assertEqual(centr.lat[2], 3)
self.assertEqual(centr.lat[3], 4)
self.assertEqual(centr.lon[0], 1)
self.assertEqual(centr.lon[1], 2)
self.assertEqual(centr.lon[2], 3)
self.assertEqual(centr.lon[3], 4)

def test_remove_duplicate_pass(self):
"""Test remove_duplicate_points"""
centr = Centroids(
Expand Down

0 comments on commit 8e08be5

Please sign in to comment.