mirror of
https://github.com/wassname/geopandas.git
synced 2026-10-02 12:20:37 +08:00
BUG: override the .equals() method from pandas to correct isinstance (#1451)
This commit is contained in:
1 parent
8f4889affd
commit
07a8f4cc7e
2 files changed
+45
-1
No files matched your search
@@ -790,6 +790,34 @@ class GeoPandasBase(object):
|
||||
"""
|
||||
return _CoordinateIndexer(self)
|
||||
|
||||
def equals(self, other):
|
||||
"""
|
||||
Test whether two objects contain the same elements.
|
||||
|
||||
This function allows two GeoSeries or GeoDataFrames to be compared
|
||||
against each other to see if they have the same shape and elements.
|
||||
Missing values in the same location are considered equal. The
|
||||
row/column index do not need to have the same type (as long as the
|
||||
values are still considered equal), but the dtypes of the respective
|
||||
columns must be the same.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other : GeoSeries or GeoDataFrame
|
||||
The other GeoSeries or GeoDataFrame to be compared with the first.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
True if all elements are the same in both objects, False
|
||||
otherwise.
|
||||
"""
|
||||
# we override this because pandas is using `self._constructor` in the
|
||||
# isinstance check (https://github.com/geopandas/geopandas/issues/1420)
|
||||
if not isinstance(other, type(self)):
|
||||
return False
|
||||
return self._data.equals(other._data)
|
||||
|
||||
|
||||
class _CoordinateIndexer(object):
|
||||
# see docstring GeoPandasBase.cx property above
|
||||
|
||||
@@ -314,6 +314,22 @@ def test_select_dtypes(df):
|
||||
assert_frame_equal(res, exp)
|
||||
|
||||
|
||||
def test_equals(s, df):
|
||||
# https://github.com/geopandas/geopandas/issues/1420
|
||||
s2 = s.copy()
|
||||
assert s.equals(s2) is True
|
||||
s2.iloc[0] = None
|
||||
assert s.equals(s2) is False
|
||||
|
||||
df2 = df.copy()
|
||||
assert df.equals(df2) is True
|
||||
df2.loc[0, "geometry"] = Point(10, 10)
|
||||
assert df.equals(df2) is False
|
||||
df2 = df.copy()
|
||||
df2.loc[0, "value1"] = 10
|
||||
assert df.equals(df2) is False
|
||||
|
||||
|
||||
# Missing values
|
||||
|
||||
|
||||
@@ -460,7 +476,7 @@ def test_groupby(df):
|
||||
|
||||
# apply on geometry column not resulting in new geometry
|
||||
res = df.groupby("value2")["geometry"].apply(lambda x: x.unary_union.area)
|
||||
exp = pd.Series([0.0, 0.0], index=pd.Index([1, 2], name="value2"), name="geometry",)
|
||||
exp = pd.Series([0.0, 0.0], index=pd.Index([1, 2], name="value2"), name="geometry")
|
||||
|
||||
assert_series_equal(res, exp)
|
||||
|
||||
|
||||
Reference in new issue
Block a user