<?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 GeoAccessor pd.DataFrame.spatial.to_table()/from_table() errors with nulls/NaNs in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/geoaccessor-pd-dataframe-spatial-to-table-from/m-p/1553733#M10823</link>
    <description>&lt;P&gt;Greetings,&lt;BR /&gt;&lt;BR /&gt;I've been struggling with both&amp;nbsp;pd.DataFrame.spatial.from_table()/to_table() methods particularly when NaNs (nulls) are in integer columns.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;First issue: spatial.to_table() will not write int64 types.&amp;nbsp; Downcasting the offending fields to int32 will fix the issue but only if you don't have NaNs which aren't allowed for int32.&amp;nbsp; Passing the offending columns as float64 will also fix the issue but introduces the second issue below.&amp;nbsp; Note: Line 9 below is not necessary because pandas reads the integer column as float64, however showing to be explicit.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_0-1730292755237.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118443iA10EE634F442046F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_0-1730292755237.png" alt="TylerT_0-1730292755237.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note: Passing float64 interestingly ends up as integer datatype in EDGB.&amp;nbsp; This image below shows EGDB table metadata.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_1-1730292889017.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118444i4BC99B119FF2DD44/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_1-1730292889017.png" alt="TylerT_1-1730292889017.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second issue: If the float64 approach above is taken then spatial_from_table() throws an error when NaNs are present in integer columns, unless skip_nulls is True (default).&amp;nbsp; Leaving skip_nulls=True is not desirable because valid rows are discarded.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;lt;with skip_nulls=True; notice only two rows returned&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_2-1730293118132.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118445iF57667AC5A4EED0C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_2-1730293118132.png" alt="TylerT_2-1730293118132.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;with skip_nulls=False&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_3-1730293236047.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118447iA83B3E35824C05AB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_3-1730293236047.png" alt="TylerT_3-1730293236047.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Changing the null_value argument to np.NaN results in same error.&lt;BR /&gt;&lt;BR /&gt;Any troubleshooting advice would be greatly appreciated.&amp;nbsp; Here is the test DataFrame constructor for your use.&lt;/P&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;LI-CODE lang="python"&gt;import pandas as pd
import numpy as np
from arcgis.features import GeoAccessor, GeoSeriesAccessor
data = {
'string_column': ['A', 'B', 'C', 'D'],
'integer_column': [1, np.NaN, 3, 4],
'float_column': [1.23, 4.56, np.NaN, 10.11],
'datetime_column': pd.to_datetime(['2024-11-22', '2024-11-23'
                                   , '2024-11-24', '2024-11-25'])
}
df = pd.DataFrame.from_dict(data)
df['integer_column'] = df['integer_column'].astype('float64')
display(df)
display(df.info())
df.spatial.to_table(location=sde / tbl)&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;&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Tyler&lt;BR /&gt;ArcGIS Pro 3.3&lt;BR /&gt;Enterprise 11.2 (MSSQL Server)&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2024 17:11:32 GMT</pubDate>
    <dc:creator>TylerT</dc:creator>
    <dc:date>2024-10-30T17:11:32Z</dc:date>
    <item>
      <title>GeoAccessor pd.DataFrame.spatial.to_table()/from_table() errors with nulls/NaNs</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/geoaccessor-pd-dataframe-spatial-to-table-from/m-p/1553733#M10823</link>
      <description>&lt;P&gt;Greetings,&lt;BR /&gt;&lt;BR /&gt;I've been struggling with both&amp;nbsp;pd.DataFrame.spatial.from_table()/to_table() methods particularly when NaNs (nulls) are in integer columns.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;First issue: spatial.to_table() will not write int64 types.&amp;nbsp; Downcasting the offending fields to int32 will fix the issue but only if you don't have NaNs which aren't allowed for int32.&amp;nbsp; Passing the offending columns as float64 will also fix the issue but introduces the second issue below.&amp;nbsp; Note: Line 9 below is not necessary because pandas reads the integer column as float64, however showing to be explicit.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_0-1730292755237.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118443iA10EE634F442046F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_0-1730292755237.png" alt="TylerT_0-1730292755237.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note: Passing float64 interestingly ends up as integer datatype in EDGB.&amp;nbsp; This image below shows EGDB table metadata.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_1-1730292889017.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118444i4BC99B119FF2DD44/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_1-1730292889017.png" alt="TylerT_1-1730292889017.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second issue: If the float64 approach above is taken then spatial_from_table() throws an error when NaNs are present in integer columns, unless skip_nulls is True (default).&amp;nbsp; Leaving skip_nulls=True is not desirable because valid rows are discarded.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;lt;with skip_nulls=True; notice only two rows returned&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_2-1730293118132.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118445iF57667AC5A4EED0C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_2-1730293118132.png" alt="TylerT_2-1730293118132.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;with skip_nulls=False&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_3-1730293236047.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118447iA83B3E35824C05AB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_3-1730293236047.png" alt="TylerT_3-1730293236047.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Changing the null_value argument to np.NaN results in same error.&lt;BR /&gt;&lt;BR /&gt;Any troubleshooting advice would be greatly appreciated.&amp;nbsp; Here is the test DataFrame constructor for your use.&lt;/P&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;LI-CODE lang="python"&gt;import pandas as pd
import numpy as np
from arcgis.features import GeoAccessor, GeoSeriesAccessor
data = {
'string_column': ['A', 'B', 'C', 'D'],
'integer_column': [1, np.NaN, 3, 4],
'float_column': [1.23, 4.56, np.NaN, 10.11],
'datetime_column': pd.to_datetime(['2024-11-22', '2024-11-23'
                                   , '2024-11-24', '2024-11-25'])
}
df = pd.DataFrame.from_dict(data)
df['integer_column'] = df['integer_column'].astype('float64')
display(df)
display(df.info())
df.spatial.to_table(location=sde / tbl)&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;&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Tyler&lt;BR /&gt;ArcGIS Pro 3.3&lt;BR /&gt;Enterprise 11.2 (MSSQL Server)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 17:11:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/geoaccessor-pd-dataframe-spatial-to-table-from/m-p/1553733#M10823</guid>
      <dc:creator>TylerT</dc:creator>
      <dc:date>2024-10-30T17:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: GeoAccessor pd.DataFrame.spatial.to_table()/from_table() errors with nulls/NaNs</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/geoaccessor-pd-dataframe-spatial-to-table-from/m-p/1566336#M10945</link>
      <description>&lt;P&gt;Have you tried casting the integer column to pd.Int32Dtype()?&amp;nbsp;&lt;/P&gt;&lt;P&gt;df[integercol] = df[integercol].astype(pd.Int32Dtype())&lt;/P&gt;&lt;P&gt;I've also had better luck with None than NaNs&lt;/P&gt;&lt;P&gt;df = df.replace({np.nan:None})&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI I've been working around this for a while in Pro 2.8.8; I'm hoping it will be improved in Pro 3. My bigest complaint is that both to_table() and to_featureclass() have issues with exporting date/number datatypes that the dataframes themselves support.&amp;nbsp; But for&amp;nbsp;some reason, to_table() is more limited than to_featureclass().&amp;nbsp; &amp;nbsp;I just had a problem where to_table failed on an integer column with empty values. So I threw on a dummy shape column, saved that using to_featureclass(), and then used ArcPy Table to Table to get the table I wanted. Very much hoping this issue was noticed and fixed long ago.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 17:37:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/geoaccessor-pd-dataframe-spatial-to-table-from/m-p/1566336#M10945</guid>
      <dc:creator>CMV_Erik</dc:creator>
      <dc:date>2024-12-09T17:37:54Z</dc:date>
    </item>
  </channel>
</rss>

