Skip to content

optimize concatenation of centroids #1125

optimize concatenation of centroids

optimize concatenation of centroids #1125

GitHub Actions / Core / Unit Test Results (3.9) failed Dec 19, 2024 in 0s

3 fail, 711 pass in 8m 34s

714 tests   711 ✅  8m 34s ⏱️
  1 suites    0 💤
  1 files      3 ❌

Results for commit cdfeac2.

Annotations

Check warning on line 0 in climada.hazard.centroids.test.test_centr.TestCentroidsMethods

See this annotation in the file changed.

@github-actions github-actions / Core / Unit Test Results (3.9)

test_append (climada.hazard.centroids.test.test_centr.TestCentroidsMethods) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: False is not true
self = <climada.hazard.centroids.test.test_centr.TestCentroidsMethods testMethod=test_append>

    def test_append(self):
        lat2, lon2 = np.array([6, 7, 8, 9, 10]), np.array([6, 7, 8, 9, 10])
        newcentr = Centroids(lat=lat2, lon=lon2)
        newcentr.append(self.centr)
>       self.assertTrue(newcentr.size == len(self.centr.lon) + len(lon2))
E       AssertionError: False is not true

climada/hazard/centroids/test/test_centr.py:803: AssertionError

Check warning on line 0 in climada.hazard.centroids.test.test_centr.TestCentroidsMethods

See this annotation in the file changed.

@github-actions github-actions / Core / Unit Test Results (3.9)

test_append_pass (climada.hazard.centroids.test.test_centr.TestCentroidsMethods) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: False is not true
self = <climada.hazard.centroids.test.test_centr.TestCentroidsMethods testMethod=test_append_pass>

    def test_append_pass(self):
        """Append points"""
        centr = self.centr
        centr_bis = Centroids(
            lat=np.array([1, 2, 3]), lon=np.array([4, 5, 6]), crs=DEF_CRS
        )
        with self.assertRaises(ValueError):
            # Different crs
            centr_bis.to_crs(ALT_CRS).append(centr)
        centr_bis.append(centr)
        self.assertAlmostEqual(centr_bis.lat[0], 1)
        self.assertAlmostEqual(centr_bis.lat[1], 2)
        self.assertAlmostEqual(centr_bis.lat[2], 3)
        self.assertAlmostEqual(centr_bis.lon[0], 4)
        self.assertAlmostEqual(centr_bis.lon[1], 5)
        self.assertAlmostEqual(centr_bis.lon[2], 6)
>       self.assertTrue(np.array_equal(centr_bis.lat[3:], centr.lat))
E       AssertionError: False is not true

climada/hazard/centroids/test/test_centr.py:796: AssertionError

Check warning on line 0 in climada.hazard.centroids.test.test_centr.TestCentroidsMethods

See this annotation in the file changed.

@github-actions github-actions / Core / Unit Test Results (3.9)

test_union (climada.hazard.centroids.test.test_centr.TestCentroidsMethods) failed

tests_xml/tests.xml [took 0s]
Raw output
AttributeError: 'Centroids' object has no attribute '_batch_gdf'
self = <climada.hazard.centroids.test.test_centr.TestCentroidsMethods testMethod=test_union>

    def test_union(self):
        lat, lon = np.array([0, 1]), np.array([0, -1])
        on_land = np.array([True, True])
        cent1 = Centroids(lat=lat, lon=lon, on_land=on_land)
    
        lat2, lon2 = np.array([2, 3]), np.array([-2, 3])
        on_land2 = np.array([False, False])
        cent2 = Centroids(lat=lat2, lon=lon2, on_land=on_land2)
    
        lat3, lon3 = np.array([-1, -2]), np.array([1, 2])
        cent3 = Centroids(lat=lat3, lon=lon3)
    
        cent = cent1.union(cent2)
        np.testing.assert_array_equal(cent.lat, np.concatenate([lat, lat2]))
        np.testing.assert_array_equal(cent.lon, np.concatenate([lon, lon2]))
        np.testing.assert_array_equal(cent.on_land, np.concatenate([on_land, on_land2]))
    
        cent = cent1.union(cent1, cent2)
        np.testing.assert_array_equal(cent.lat, np.concatenate([lat, lat2]))
        np.testing.assert_array_equal(cent.lon, np.concatenate([lon, lon2]))
        np.testing.assert_array_equal(cent.on_land, np.concatenate([on_land, on_land2]))
    
>       cent = Centroids.union(cent1)

climada/hazard/centroids/test/test_centr.py:872: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
climada/hazard/centroids/centr.py:404: in union
    centroids.finalize_append()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <climada.hazard.centroids.centr.Centroids object at 0x7fefeb519370>

    def finalize_append(self):
        """Concatenate all batch-appended centroids into the main GeoDataFrame (gdf).
    
        This method should be called after all `append` operations have been performed on the
        Centroids object. It concatenates all the accumulated GeoDataFrames stored in the
        `_batch_gdf` list into the `gdf` attribute of the Centroids object. By doing this in one
        step, it avoids the performance overhead associated with repeated concatenations.
    
        Once concatenation is complete, the `_batch_gdf` list is cleared to prepare for future
        append operations.
        """
    
>       self.gdf = pd.concat([self.gdf] + self._batch_gdf, ignore_index=True)
E       AttributeError: 'Centroids' object has no attribute '_batch_gdf'

climada/hazard/centroids/centr.py:382: AttributeError