arcgis-python-api icon indicating copy to clipboard operation
arcgis-python-api copied to clipboard

GeoSeriesAccessor.equals returns None in version 2.2

Open skykasko opened this issue 11 months ago • 2 comments

Describe the bug After updating to version: 2.2.0.1 of the API, the GeoSeriesAccessor.equals() method always returns None.

To Reproduce

import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor

spatial_reference = {"wkid": 102100, "latestWkid": 3857}
df1 = pd.DataFrame(
    [
        {"SHAPE": {"x": -7000000, "y": 5000000, "spatialReference": spatial_reference}},
        {"SHAPE": {"x": -7000001, "y": 5000001, "spatialReference": spatial_reference}},
    ]
)
df2 = pd.DataFrame(
    [
        {"SHAPE": {"x": -7000000, "y": 5000000, "spatialReference": spatial_reference}},
        {"SHAPE": {"x": -7000002, "y": 5000002, "spatialReference": spatial_reference}},
    ]
)
print(df1[df1.spatial.name].geom.equals(df2[df2.spatial.name]))
# None

Running the exact same code in version 2.1.0.2 of the API yields the expected result:

print(df1[df1.spatial.name].geom.equals(df2[df2.spatial.name]))
# 0     True
# 1    False
# Name: equals, dtype: bool

Expected behavior The equals() method should return a Pandas Series of booleans like it did prior to version 2.2 of the API.

Platform (please complete the following information):

  • OS: Windows 10
  • Python API version: 2.2.0.1

Additional context I use GeoSeriesAccessor.equals() as part of a custom comparison method that returns the differences between two Spatially Enabled DataFrames; updating to version 2.2 of the API broke my workflow. I looked into replacing my custom method with the new GeoAccessor.compare() method, and ran into issue https://github.com/Esri/arcgis-python-api/issues/1766.

skykasko avatar Feb 29 '24 20:02 skykasko

@skykasko

You are right the functionality changed. We will fix this. To get an output other than None you need to change: print(df1[df1.spatial.name].geom.equals(df2[df2.spatial.name])) to be print(df1[df1.spatial.name].geom.equals(df2[df2.spatial.name].geom))

nanaeaubry avatar Mar 01 '24 08:03 nanaeaubry

Thanks for the suggestion. I tried df1[df1.spatial.name].geom.equals(df2[df2.spatial.name].geom) and the output is False, still not the Pandas Series of booleans I expected.

skykasko avatar Mar 01 '24 16:03 skykasko

@skykasko We put in a fix for 2.3.0 which will be in beta release soon and final release by April.

Another suggestion to check each shape is to use the equals found in the Geometry class.

import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor

spatial_reference = {"wkid": 102100, "latestWkid": 3857}
df1 = pd.DataFrame(
    [
        {"SHAPE": {"x": -7000000, "y": 5000000, "spatialReference": spatial_reference}},
        {"SHAPE": {"x": -7000001, "y": 5000001, "spatialReference": spatial_reference}},
    ]
)
df2 = pd.DataFrame(
    [
        {"SHAPE": {"x": -7000000, "y": 5000000, "spatialReference": spatial_reference}},
        {"SHAPE": {"x": -7000002, "y": 5000002, "spatialReference": spatial_reference}},
    ]
)

equals_list = []
for i in range(len(df1)):
    equals_list.append(df1[df1.spatial.name].iloc[i].equals(df2[df2.spatial.name].iloc[i]))
print(equals_list)

It still won't be a pandas series for 2.2.x but rather a list you construct.

nanaeaubry avatar Mar 04 '24 11:03 nanaeaubry