Inconsistency of Global ID Column

07-20-2021 02:02 AM
New Contributor II

Hi All,

Does anyone have any issue with inconsistency in global id field name when using geoaccessor in python AP? I am using it for converting a feature class to dataframe and the global id field name randomly changes (either 'globalid', 'GlobalID', or 'global_id'.

Please share if you have some configurations or workaround to prevent this from happening.


0 Kudos
3 Replies
Esri Contributor

Hi @MuhammadNaufalIhsan,

Have you checked the name of your global ID field in the feature layers/tables that you are reading into a dataframe?

I have seen this before, but it turned out to be the case that my field names were actually different to begin with. As a workaround, perhaps you could try the following:

from arcgis.gis import GIS
from arcgis.features import GeoAccessor
import pandas as pd

gis = GIS("home")

item = gis.content.get("<itemid>")
flayer = item.layers[0]

sedf = pd.DataFrame.spatial.from_layer(flayer)

for column in sedf:
    if column == 'globalid':
        sedf = sedf.rename(columns={'globalid': 'GlobalID'})
    elif column == 'global_id':
        sedf = sedf.rename(columns={'global_id': 'GlobalID'})

0 Kudos
New Contributor II

Hi @HamishMorton,

Thank you for your response. Yes, I've checked the name of the field (it is 'globalid'). I've run the tools on pro and it is going well. But once I've published to GP service and run it on web app, it shows an error that says "key 'globalid' does not exist." When I troubleshoot the problem, it turns out the name sometimes changes to either 'global_id' or 'GlobalID.'

So far, I force the field name to change to 'globalid' in pandas as a workaround. But I've just wondered whether this is a common problem or not.

Thank you.

0 Kudos
New Contributor III

To complement Hamish's answer, if you simply wanted to know the globalid field, you could do so like so:




import pandas as pd
from arcgis import GIS
from arcgis.features import FeatureLayer

gis = GIS("your_org_url", "username", "password")
fl_url = "whatever/your/url/is/0"
fl= FeatureLayer(table_url, gis=gis)
globalid_field = if hasattr(, "globalIdField") else None

query_results =  fl.query()
sdf = query_results.sdf
# Do something with sdf[globalid_field]




I don't know about you, but I often need to know the globalid field without hardcoding a value so as to make scripts more versatile. If that's what' you're after I think this logic will be useful to you.