mirror of
https://github.com/wassname/geopandas.git
synced 2026-10-04 12:40:08 +08:00
ENH: support pd.NA value as missing value (#1448)
* support pd.NA * skip tests * doctsring, check
This commit is contained in:
1 parent
25f60648ab
commit
cfbf5d6536
2 files changed
+17
-1
No files matched your search
+3
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user