From 0f1debae995018d157c8ea3cc37befe017308207 Mon Sep 17 00:00:00 2001 From: Jacob Wasserman Date: Sat, 16 Nov 2013 14:23:32 -0500 Subject: [PATCH] Rename equals methods to geom_equals Renames on GeoPandasBase: * equals() -> geom_equals() * almost_equals() -> geom_almost_equals() * equals_exact() -> geom_equals_exact() --- geopandas/base.py | 6 +++--- geopandas/geoseries.py | 2 +- tests/test_geodataframe.py | 2 +- tests/test_geom_methods.py | 2 +- tests/test_geoseries.py | 26 +++++++++++++------------- tests/util.py | 5 +++-- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/geopandas/base.py b/geopandas/base.py index 997032d..7a57273 100644 --- a/geopandas/base.py +++ b/geopandas/base.py @@ -160,16 +160,16 @@ class GeoPandasBase(object): """Return True for all geometries that contain *other*, else False""" return _series_op(self, other, 'contains') - def equals(self, other): + def geom_equals(self, other): """Return True for all geometries that equal *other*, else False""" return _series_op(self, other, 'equals') - def almost_equals(self, other, decimal=6): + def geom_almost_equals(self, other, decimal=6): """Return True for all geometries that is approximately equal to *other*, else False""" # TODO: pass precision argument return _series_op(self, other, 'almost_equals', decimal=decimal) - def equals_exact(self, other, tolerance): + def geom_equals_exact(self, other, tolerance): """Return True for all geometries that equal *other* to a given tolerance, else False""" # TODO: pass tolerance argument. return _series_op(self, other, 'equals_exact', tolerance=tolerance) diff --git a/geopandas/geoseries.py b/geopandas/geoseries.py index b8a9bc6..077a9cb 100644 --- a/geopandas/geoseries.py +++ b/geopandas/geoseries.py @@ -204,7 +204,7 @@ class GeoSeries(GeoPandasBase, Series): Note: This is not the same as the geometric method "contains". """ if isinstance(other, BaseGeometry): - return np.any(self.equals(other)) + return np.any(self.geom_equals(other)) else: return False diff --git a/tests/test_geodataframe.py b/tests/test_geodataframe.py index 3fd6023..4d32d43 100644 --- a/tests/test_geodataframe.py +++ b/tests/test_geodataframe.py @@ -278,7 +278,7 @@ class TestDataFrame(unittest.TestCase): df2.crs = {'init': 'epsg:26918', 'no_defs': True} lonlat = df2.to_crs(epsg=4326) utm = lonlat.to_crs(epsg=26918) - self.assertTrue(all(df2['geometry'].almost_equals(utm['geometry'], decimal=2))) + self.assertTrue(all(df2['geometry'].geom_almost_equals(utm['geometry'], decimal=2))) def test_from_postgis_default(self): con = connect('test_geopandas') diff --git a/tests/test_geom_methods.py b/tests/test_geom_methods.py index 56d2328..d4f6efd 100644 --- a/tests/test_geom_methods.py +++ b/tests/test_geom_methods.py @@ -306,7 +306,7 @@ class TestGeomMethods(unittest.TestCase): def test_envelope(self): e = self.g3.envelope - self.assertTrue(np.alltrue(e.equals(self.sq))) + self.assertTrue(np.alltrue(e.geom_equals(self.sq))) self.assertIsInstance(e, GeoSeries) self.assertEqual(self.g3.crs, e.crs) diff --git a/tests/test_geoseries.py b/tests/test_geoseries.py index e9f173e..d2f36d7 100644 --- a/tests/test_geoseries.py +++ b/tests/test_geoseries.py @@ -79,12 +79,12 @@ class TestSeries(unittest.TestCase): self.assertTrue(self.sq not in self.g3) self.assertTrue(5 not in self.g3) - def test_equals(self): - self.assertTrue(np.alltrue(self.g1.equals(self.g1))) - assert_array_equal(self.g1.equals(self.sq), [False, True]) + def test_geom_equals(self): + self.assertTrue(np.alltrue(self.g1.geom_equals(self.g1))) + assert_array_equal(self.g1.geom_equals(self.sq), [False, True]) - def test_equals_align(self): - a = self.a1.equals(self.a2) + def test_geom_equals_align(self): + a = self.a1.geom_equals(self.a2) self.assertFalse(a['A']) self.assertTrue(a['B']) self.assertFalse(a['C']) @@ -95,15 +95,15 @@ class TestSeries(unittest.TestCase): self.assertTrue(a1['B'].equals(a2['B'])) self.assertTrue(a1['C'].is_empty) - def test_almost_equals(self): + def test_geom_almost_equals(self): # TODO: test decimal parameter - self.assertTrue(np.alltrue(self.g1.almost_equals(self.g1))) - assert_array_equal(self.g1.almost_equals(self.sq), [False, True]) + self.assertTrue(np.alltrue(self.g1.geom_almost_equals(self.g1))) + assert_array_equal(self.g1.geom_almost_equals(self.sq), [False, True]) - def test_equals_exact(self): + def test_geom_equals_exact(self): # TODO: test tolerance parameter - self.assertTrue(np.alltrue(self.g1.equals_exact(self.g1, 0.001))) - assert_array_equal(self.g1.equals_exact(self.sq, 0.001), [False, True]) + self.assertTrue(np.alltrue(self.g1.geom_equals_exact(self.g1, 0.001))) + assert_array_equal(self.g1.geom_equals_exact(self.sq, 0.001), [False, True]) def test_to_file(self): """ Test to_file and from_file """ @@ -111,7 +111,7 @@ class TestSeries(unittest.TestCase): self.g3.to_file(tempfilename) # Read layer back in? s = GeoSeries.from_file(tempfilename) - self.assertTrue(all(self.g3.equals(s))) + self.assertTrue(all(self.g3.geom_equals(s))) # TODO: compare crs def test_representative_point(self): @@ -123,7 +123,7 @@ class TestSeries(unittest.TestCase): def test_transform(self): utm18n = self.landmarks.to_crs(epsg=26918) lonlat = utm18n.to_crs(epsg=4326) - self.assertTrue(np.alltrue(self.landmarks.almost_equals(lonlat))) + self.assertTrue(np.alltrue(self.landmarks.geom_almost_equals(lonlat))) with self.assertRaises(ValueError): self.g1.to_crs(epsg=4326) with self.assertRaises(TypeError): diff --git a/tests/util.py b/tests/util.py index 8b390f7..c3a6b26 100644 --- a/tests/util.py +++ b/tests/util.py @@ -120,7 +120,7 @@ def geom_equals(this, that): attribute) """ - return (this.equals(that) | (this.is_empty & that.is_empty)).all() + return (this.geom_equals(that) | (this.is_empty & that.is_empty)).all() def geom_almost_equals(this, that): @@ -132,7 +132,8 @@ def geom_almost_equals(this, that): property) """ - return (this.almost_equals(that) | (this.is_empty & that.is_empty)).all() + return (this.geom_almost_equals(that) | + (this.is_empty & that.is_empty)).all() # TODO: Remove me when standardizing on pandas 0.13, which already includes # this test util.