From d6932671c66c6fa36bd145f3053d8a5d1f2dd4e0 Mon Sep 17 00:00:00 2001 From: "Alan D. Snow" Date: Mon, 14 Sep 2020 03:34:24 -0500 Subject: [PATCH] BUG: Handle missing geometry with to_crs and shapely (#1618) * BUG: Handle missing geometry with to_crs and shapely * remove pygeos compat stuff in tests --- geopandas/_vectorized.py | 5 ++++- geopandas/tests/test_crs.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/geopandas/_vectorized.py b/geopandas/_vectorized.py index d31cfc9..673cb39 100644 --- a/geopandas/_vectorized.py +++ b/geopandas/_vectorized.py @@ -886,6 +886,9 @@ def transform(data, func): result = np.empty(n, dtype=object) for i in range(n): geom = data[i] - result[i] = transform(func, geom) + if _isna(geom): + result[i] = geom + else: + result[i] = transform(func, geom) return result diff --git a/geopandas/tests/test_crs.py b/geopandas/tests/test_crs.py index 2936d00..a804d4b 100644 --- a/geopandas/tests/test_crs.py +++ b/geopandas/tests/test_crs.py @@ -49,6 +49,15 @@ def test_to_crs_transform(): assert_geodataframe_equal(df, utm, check_less_precise=True) +def test_to_crs_transform__missing_data(): + # https://github.com/geopandas/geopandas/issues/1573 + df = df_epsg26918() + df.loc[3, "geometry"] = None + lonlat = df.to_crs(epsg=4326) + utm = lonlat.to_crs(epsg=26918) + assert_geodataframe_equal(df, utm, check_less_precise=True) + + def test_to_crs_inplace(): df = df_epsg26918() lonlat = df.to_crs(epsg=4326)