<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: .to_featureclass() incorrectly tries to convert to float in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377976#M9624</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/661245"&gt;@bland&lt;/a&gt;&amp;nbsp;that does sound complicated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;With that in mind, hopefully&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/86309"&gt;@EarlMedina&lt;/a&gt;'s comments about using a FeatureSet, rather than a FeatureLayer, will help you get on the right track with using edit_features.&lt;/P&gt;&lt;P&gt;The details are always important though, so if your use case involves editing more than ~250 records, then you should consider the note in the documentation for &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.edit_features" target="_self"&gt;edit_features&amp;nbsp;&lt;/A&gt;about using &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.append" target="_self"&gt;append&lt;/A&gt; instead with edits/upsert.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Feb 2024 16:06:41 GMT</pubDate>
    <dc:creator>PeterKnoop</dc:creator>
    <dc:date>2024-02-04T16:06:41Z</dc:date>
    <item>
      <title>.to_featureclass() incorrectly tries to convert to float</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377743#M9617</link>
      <description>&lt;P&gt;I am trying to write a script that can be automated and will pull down a feature layer, check a field, alter the value based on a condition, and then updates the feature layer. To do this, I am using (generalized):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.features import GeoAccessor, GeoSeriesAccessor

gis = GIS(URL, username, password)

item1content = gis.content.get(item1id)
item1 = item1content.layers[0]

df = points_layer.query().sdf

# complicated bit of logic
# if condition is true, df['scored'] = 1, if false, df['scored'] = 0

points_features = df.spatial.to_featurelayer('Points Features') # &amp;lt;- tripping point
edit_result = item1.edit_features(updates=points_features.features)
if 'success' in edit_result:
    print(f"Data in {item1.title} has been updated successfully.")
else:
    print("Edit features operation failed. Check the error message for details.")
    print(edit_result['error'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This bit has been troublesome, and I assume it has to do with the datatypes in the dataframe being incompatible with the datatypes for the feature layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The current error message:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;ValueError: could not convert string to float: 'test@test.com'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This obviously makes sense, but the df field for email (which is never manipulated) is a "string[python]". Why is it trying to force it to be a float? I can't find any documentation or example on how to force field types or anything. Do I need to use "sanitize columns" and then overwrite the types?&lt;/P&gt;&lt;P&gt;The exact error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;ValueError                                Traceback (most recent call last)
Cell In[42], line 1
----&amp;gt; 1 points_features = scored_df.spatial.to_featurelayer('Scored Points')
      2 edit_result = points_layer.edit_features(updates=points_features.features)
      3 if 'success' in edit_result:

File /path/to/lib/python3.8/site-packages/arcgis/features/geo/_accessor.py:2846, in GeoAccessor.to_featurelayer(self, title, gis, tags, folder, sanitize_columns, service_name, **kwargs)
   2838     if (
   2839         content.is_service_name_available(service_name, "featureService")
   2840         is False
   2841     ):
   2842         raise ValueError(
   2843             "This service name is unavailable for Feature Service."
   2844         )
-&amp;gt; 2846 result = content.import_data(
   2847     self._data,
   2848     folder=folder,
   2849     title=title,
   2850     tags=tags,
   2851     sanitize_columns=sanitize_columns,
   2852     service_name=service_name,
   2853     **kwargs,
   2854 )
   2855 self._data.columns = origin_columns
   2856 self._data.index = origin_index

File /path/to/lib/python3.8/site-packages/arcgis/gis/__init__.py:7569, in ContentManager.import_data(self, df, address_fields, folder, item_id, **kwargs)
   7563 elif has_pyshp:
   7564     name = "%s%s.shp" % (
   7565         random.choice(string.ascii_lowercase),
   7566         uuid4().hex[:5],
   7567     )
-&amp;gt; 7569     ds = df.spatial.to_featureclass(
   7570         location=os.path.join(temp_dir, name),
   7571         sanitize_columns=sanitize_columns,
   7572     )
   7573     zip_shp = zipws(path=temp_dir, outfile=temp_zip, keep=False)
   7574     item = self.add(
   7575         item_properties={"title": title, "tags": tags},
   7576         data=zip_shp,
   7577         folder=folder,
   7578     )

File /path/to/lib/python3.8/site-packages/arcgis/features/geo/_accessor.py:2637, in GeoAccessor.to_featureclass(self, location, overwrite, has_z, has_m, sanitize_columns)
   2635 origin_columns = self._data.columns.tolist()
   2636 origin_index = copy.deepcopy(self._data.index)
-&amp;gt; 2637 result = to_featureclass(
   2638     self,
   2639     location=location,
   2640     overwrite=overwrite,
   2641     has_z=has_z,
   2642     sanitize_columns=sanitize_columns,
   2643     has_m=has_m,
   2644 )
   2645 self._data.columns = origin_columns
   2646 self._data.index = origin_index

File /path/to/lib/python3.8/site-packages/arcgis/features/geo/_io/fileops.py:1108, in to_featureclass(geo, location, overwrite, validate, sanitize_columns, has_m, has_z)
   1106     return res
   1107 else:
-&amp;gt; 1108     res = _pyshp2(df=df, out_path=out_location, out_name=fc_name)
   1109     df.set_index(old_idx)
   1110     return res

File /path/to/lib/python3.8/site-packages/arcgis/features/geo/_io/fileops.py:1336, in _pyshp2(df, out_path, out_name)
   1334     if value is np.nan:
   1335         row[idx] = None
-&amp;gt; 1336 shpfile.record(*row)
   1337 del idx
   1338 del row

File /path/to/lib/python3.8/site-packages/shapefile.py:2300, in Writer.record(self, *recordList, **recordDict)
   2297 else:
   2298     # Blank fields for empty record
   2299     record = ["" for _ in range(fieldCount)]
-&amp;gt; 2300 self.__dbfRecord(record)

File /path/to/lib/python3.8/site-packages/shapefile.py:2335, in Writer.__dbfRecord(self, record)
   2333         value = format(value, "d")[:size].rjust(size) # caps the size if exceeds the field size
   2334     else:
-&amp;gt; 2335         value = float(value)
   2336         value = format(value, ".%sf"%deci)[:size].rjust(size) # caps the size if exceeds the field size
   2337 elif fieldType == "D":
   2338     # date: 8 bytes - date stored as a string in the format YYYYMMDD.

ValueError: could not convert string to float: 'test@test.com'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can get around this error, but always run into another error. For example, if I explicitly convert the GeoDF back to a SEDF via "scored_sedf = GeoAccessor.from_geodataframe(df, column_name="geometry")", I now get a "AttributeError: 'Series' object has no attribute 'type'" during to_featureclass().&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 19:45:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377743#M9617</guid>
      <dc:creator>BlakeMunshell</dc:creator>
      <dc:date>2024-02-02T19:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: .to_featureclass() incorrectly tries to convert to float</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377798#M9618</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Have you tried using&amp;nbsp;df.spatial.to_featureset() instead? I'm not sure if you'll encounter the same issue, but if all you need "point_features" for is to update "item1" then there's not much point in publishing the intermediate data.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 22:39:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377798#M9618</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2024-02-02T22:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: .to_featureclass() incorrectly tries to convert to float</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377844#M9620</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/648001"&gt;@BlakeMunshell&lt;/a&gt;&amp;nbsp;there are lots of different ways to accomplish your overall goal. If you can implement your "complicated bit of logic" in Arcade, then you could reduce this to simply, "&lt;SPAN&gt;alter the value based on a condition" using&amp;nbsp;&lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.geoanalytics.manage_data.html#calculate-fields" target="_self"&gt;arcgis.geoanalytics.manage_data.calculate_fields&lt;/A&gt;, enabling you to skip the pull-down, check, and update steps.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 22:03:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377844#M9620</guid>
      <dc:creator>PeterKnoop</dc:creator>
      <dc:date>2024-02-02T22:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: .to_featureclass() incorrectly tries to convert to float</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377909#M9623</link>
      <description>&lt;P&gt;As much as I would love to use Arcade, my logic is more "complicated" than it is "bit". It's a few hundred lines of checking data against other layers and using other libraries, and then updating binary fields that I am using as flags on the data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I might try to convert the SEDF to a JSON (as shown &lt;A href="https://developers.arcgis.com/python/samples/updating-features-in-a-feature-layer/#Updating-feature-layer-by-editing-individual-features" target="_self"&gt;here&lt;/A&gt;), and then use the keys to update specifically the fields that need to be updated rather than entire records. Since "email" never has to get updated, I can try to just skip over that field.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Feb 2024 13:37:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377909#M9623</guid>
      <dc:creator>BlakeMunshell</dc:creator>
      <dc:date>2024-02-03T13:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: .to_featureclass() incorrectly tries to convert to float</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377976#M9624</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/661245"&gt;@bland&lt;/a&gt;&amp;nbsp;that does sound complicated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;With that in mind, hopefully&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/86309"&gt;@EarlMedina&lt;/a&gt;'s comments about using a FeatureSet, rather than a FeatureLayer, will help you get on the right track with using edit_features.&lt;/P&gt;&lt;P&gt;The details are always important though, so if your use case involves editing more than ~250 records, then you should consider the note in the documentation for &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.edit_features" target="_self"&gt;edit_features&amp;nbsp;&lt;/A&gt;about using &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.append" target="_self"&gt;append&lt;/A&gt; instead with edits/upsert.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 16:06:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/to-featureclass-incorrectly-tries-to-convert-to/m-p/1377976#M9624</guid>
      <dc:creator>PeterKnoop</dc:creator>
      <dc:date>2024-02-04T16:06:41Z</dc:date>
    </item>
  </channel>
</rss>

