I have some previously working code that is now failing. I am fairly certain I was using Pro version 2.5 when I last had it working (arcgis.__version__: 1.8.0, pandas.__version__: 0.25.1, Python: 3.6.9). I am currently in Pro 2.9.1 (arcgis.__version__: 1.9.1, pandas.__version__: 1.2.3, Python: 3.7.11).
>>> import arcpy
>>> import pandas as pd
>>> arcpy.env.workspace = "<path_to_fgdb>"
>>> sel_fc = arcpy.management.SelectLayerByAttribute("ACS2020_County",
>>> selection_type='NEW_SELECTION',
>>> where_clause="State_FIPS in ('15')")
>>> type(sel_fc)
<class 'arcpy.arcobjects.arcobjects.Result'>
>>> sdf = pd.DataFrame.spatial.from_featureclass(sel_fc)
In Pro 2.9.1, it is returning an Exception of type ValueError:
ValueError: filename must be a `str`, `Path`, or `PurePath`, not <class 'arcpy.arcobjects.arcobjects.Result'>
I see 3 work-arounds for this, all sub-optimal:
- Save the selection to a feature class (seems like a hassle, might be slow, and requires clean-up later)
- Read the entire feature class with pd.DataFrame.spatial.from_featureclass and then do my selection in Pandas. For a trivial example like this, it's fine, but if the selection is more complicated and/or spatial, I wouldn't want to lose the capability to use ArcPy's selection.
- Downgrading the versions of modules in my Conda environment -- I really don't want to go down this path...
Before I go any of these routes, I'm curious if anyone has also seen this behavior and has a way to work with a selection set.