From cfbf5d6536dda3e31b5edc732515b0ac830fa148 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Mon, 25 May 2020 19:48:39 +0100 Subject: [PATCH] ENH: support pd.NA value as missing value (#1448) * support pd.NA * skip tests * doctsring, check --- geopandas/array.py | 4 +++- geopandas/tests/test_array.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/geopandas/array.py b/geopandas/array.py index 19fd432..4c111f1 100644 --- a/geopandas/array.py +++ b/geopandas/array.py @@ -55,7 +55,7 @@ if compat.PANDAS_GE_024: def _isna(value): """ - Check if scalar value is NA-like (None or np.nan). + Check if scalar value is NA-like (None, np.nan or pd.NA). Custom version that only works for scalars (returning True or False), as `pd.isna` also works for array-like input returning a boolean array. @@ -64,6 +64,8 @@ def _isna(value): return True elif isinstance(value, float) and np.isnan(value): return True + elif compat.PANDAS_GE_10 and value is pd.NA: + return True else: return False diff --git a/geopandas/tests/test_array.py b/geopandas/tests/test_array.py index 90b28c1..6d35860 100644 --- a/geopandas/tests/test_array.py +++ b/geopandas/tests/test_array.py @@ -822,3 +822,17 @@ def test_check_crs(): assert _check_crs(t1, T) is False assert _check_crs(t1, t1) is True assert _check_crs(t1, T, allow_none=True) is True + + +@pytest.mark.parametrize("NA", [None, np.nan]) +def test_isna(NA): + t1 = T.copy() + t1[0] = NA + assert t1[0] is None + + +@pytest.mark.skipif(not compat.PANDAS_GE_10, reason="pd.NA introduced in pandas 1.0") +def test_isna_pdNA(): + t1 = T.copy() + t1[0] = pd.NA + assert t1[0] is None