Skip to content

Commit

Permalink
COMPAT: Alias isnull -> isna, following pandas (geopandas#517)
Browse files Browse the repository at this point in the history
* COMPAT: Alias isnull -> isna, following pandas

Add same alias for notnull -> notna, and add tests of empty geometries
to ensure that the check is working for the case it is supposed to
catch.
  • Loading branch information
jdmcbr authored and jorisvandenbossche committed Aug 27, 2017
1 parent 8b40eda commit 8054456
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
42 changes: 40 additions & 2 deletions geopandas/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,50 @@ def copy(self, order='C'):
return GeoSeries(self.values.copy(order), index=self.index,
name=self.name).__finalize__(self)

def isnull(self):
"""Null values in a GeoSeries are represented by empty geometric objects"""
def isna(self):
"""
N/A values in a GeoSeries can be represented by empty geometric
objects, in addition to standard representations such as None and
np.nan.
Returns
-------
A boolean pandas Series of the same size as the GeoSeries,
True where a value is N/A.
See Also
--------
GeoSereies.notna : inverse of isna
"""
non_geo_null = super(GeoSeries, self).isnull()
val = self.apply(_is_empty)
return np.logical_or(non_geo_null, val)

def isnull(self):
"""Alias for `isna` method. See `isna` for more detail."""
return self.isna()

def notna(self):
"""
N/A values in a GeoSeries can be represented by empty geometric
objects, in addition to standard representations such as None and
np.nan.
Returns
-------
A boolean pandas Series of the same size as the GeoSeries,
False where a value is N/A.
See Also
--------
GeoSeries.isna : inverse of notna
"""
return ~self.isna()

def notnull(self):
"""Alias for `notna` method. See `notna` for more detail."""
return self.notna()

def fillna(self, value=None, method=None, inplace=False,
**kwargs):
"""Fill NA/NaN values with a geometry (empty polygon by default).
Expand Down
22 changes: 13 additions & 9 deletions geopandas/tests/test_pandas_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import pandas as pd
import shapely
from shapely.geometry import Point
from shapely.geometry import Point, Polygon

from geopandas import GeoDataFrame, GeoSeries
from geopandas.tests.util import assert_geoseries_equal
Expand Down Expand Up @@ -176,14 +176,18 @@ def test_dropna():
assert_geoseries_equal(res, exp)


def test_isnull():
for NA in [None, np.nan]:
s2 = GeoSeries([Point(0, 0), NA, Point(2, 2)])
res = s2.isnull()
exp = pd.Series([False, True, False])
assert_series_equal(res, exp)
res = s2.notnull()
assert_series_equal(res, ~exp)
@pytest.mark.parametrize("NA", [None, np.nan, Point(), Polygon()])
def test_isna(NA):
s2 = GeoSeries([Point(0, 0), NA, Point(2, 2)])
exp = pd.Series([False, True, False])
res = s2.isnull()
assert_series_equal(res, exp)
res = s2.isna()
assert_series_equal(res, exp)
res = s2.notnull()
assert_series_equal(res, ~exp)
res = s2.notna()
assert_series_equal(res, ~exp)


# Groupby / algos
Expand Down

0 comments on commit 8054456

Please sign in to comment.