Hello! I am having an issue when trying to export a spatially enabled dataframe to a feature class or feature layer using the arcgis package for python. I receive the error "TypeError: '<' not supported between instances of 'tuple' and 'float'".
For background, I am importing a shapefile into a sedf using pd.DataFrame.spatial.from_featureclass() (success!), joining this sdf with another df that has economic information (success!), and would like to return this to a shapefile or upload to Arcgis enterprise (failure).
My code when trying to create a local shapefile:
TypeError Traceback (most recent call last)
program.py in <module>
----> 79 disaster_areas.spatial.to_featureclass(location=r"local/location/output.shp")
C:\Anaconda3_2021.11\lib\site-packages\arcgis\features\geo\_accessor.py in to_featureclass(self, location, overwrite)
1838 def to_featureclass(self, location, overwrite=True):
1839 """exports a geo enabled dataframe to a feature class."""
-> 1840 return to_featureclass(geo=self,
C:\Anaconda3_2021.11\lib\site-packages\arcgis\features\geo\_io\fileops.py in to_featureclass(geo, location, overwrite, validate)
584 fc_name = "%s.shp" % fc_name
585 if SHPVERSION < :
--> 586 return _pyshp_to_shapefile(df=df,
C:\Anaconda3_2021.11\lib\site-packages\arcgis\features\geo\_io\fileops.py in _pyshp_to_shapefile(df, out_path, out_name)
679 del row
680 del geom
--> 681 shpfile.save(out_fc)
C:\Anaconda3_2021.11\lib\site-packages\shapefile.py in save(self, target, shp, shx, dbf)
1111 target = temp.name
1112 generated = True
-> 1113 self.saveShp(target)
C:\Anaconda3_2021.11\lib\site-packages\shapefile.py in saveShp(self, target)
1067 self.shapeType = next((s.shapeType for s in self._shapes if s.shapeType), NULL)
1068 self.shp = self.__getFileObj(target)
-> 1069 self.__shapefileHeader(self.shp, headerType='shp')
C:\Anaconda3_2021.11\lib\site-packages\shapefile.py in __shapefileHeader(self, fileObj, headerType)
752 if self.shapeType != 0:
--> 754 f.write(pack("<4d", *self.bbox()))
755 except error:
756 raise ShapefileException("Failed to write shapefile bounding box. Floats required.")
C:\Anaconda3_2021.11\lib\site-packages\shapefile.py in bbox(self)
724 the lower-left and upper-right corners. It does not contain the
725 elevation or measure extremes."""
--> 726 return self.__bbox(self._shapes)
728 def zbox(self):
C:\Anaconda3_2021.11\lib\site-packages\shapefile.py in __bbox(self, shapes)
696 if len(x) == 0:
697 return  * 4
--> 698 return [min(x), min(y), max(x), max(y)]
700 def __zbox(self, shapes):
TypeError: '<' not supported between instances of 'tuple' and 'float'
Not to be tiresome but many people think shapefile suck and even though they invented them Esri programmers might not give them complete attention. So have you tried writing to a file geodatabase instead? I know you said you tried going to Enterprise too but that's a whole nother can of worms.
I worked through a process similar to yours, let me dig around and find it...
I dug up my code, changed the output path from FGDB to shapefile, and ran it.
I had one problem, my script sets field name aliases and that fails for a shapefile. (I can set aliases in ArcGIS Pro, so this is another bug. I used arcpy.management.AlterField. But I digress.)
One debugging tip that helps me is to dump out the dtypes in a dataframe to see if they make sense.
print(len(sdf)) print(sdf.columns) print(sdf.dtypes)
Curious! I've not had that happen before, though I admittedly do not export to shapefiles much.
Similar to @Brian_Wilson , I would first confirm if any other export format works, including the non-file options like FeatureCollection and FeatureSet, just to confirm if it's an issue with the format, as opposed to the data itself.
Based on the error you got, it sounds like something is wrong with the bounding box. Can you output the dataframes' bbox property and see if it's changing over the course of your join operations?