Rename equals methods to geom_equals

Renames on GeoPandasBase:
* equals() -> geom_equals()
* almost_equals() -> geom_almost_equals()
* equals_exact() -> geom_equals_exact()
This commit is contained in:
Jacob Wasserman
2013-12-27 11:17:46 -05:00
parent 8db12e6d49
commit 0f1debae99
6 changed files with 22 additions and 21 deletions
+3 -3
View File
@@ -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)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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')
+1 -1
View File
@@ -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)
+13 -13
View File
@@ -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):
+3 -2
View File
@@ -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.