<?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 Notebook server spatial dataframe date from query result parsed wrong in ArcGIS Notebooks Questions</title>
    <link>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1022906#M245</link>
    <description>&lt;P&gt;I'm currently testing a Notebook server standard 10.8.1 and see some strange behavior on date fields in the spatial data frame.&lt;/P&gt;&lt;P&gt;I get a layer from my ArcGIS Enterprise:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_0-1612336963824.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5198i7B8C0AF24C27DAAC/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_0-1612336963824.png" alt="JoëlHempenius3_0-1612336963824.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I do a query with a geometry filter on that layer and specify the out fields&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_1-1612337009286.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5199i7D3E61BBBE9F4948/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_1-1612337009286.png" alt="JoëlHempenius3_1-1612337009286.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And from the result I get the spatial data frame:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_2-1612337102018.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5200iF22744EFBC33870F/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_2-1612337102018.png" alt="JoëlHempenius3_2-1612337102018.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note that all dates in DATUM_AANLEG column are close to unix epoch time.&lt;/P&gt;&lt;P&gt;When I get feature with OBJECTID 17296550&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_3-1612337205274.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5201iE1B120812ABBA4EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_3-1612337205274.png" alt="JoëlHempenius3_3-1612337205274.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and I convert the date manually, (javascript console new Date(1403748000000) ) I get&amp;nbsp;Thu Jun 26 2014 04:00:00 GMT+0200 (Midden-Europese zomertijd), which is the correct date.&lt;/P&gt;&lt;P&gt;Clearly, something goes wrong when querying the service and converting the results to the spatial data frame. But I do not see where and how I can fix it.&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Feb 2021 07:30:03 GMT</pubDate>
    <dc:creator>JoëlHempenius3</dc:creator>
    <dc:date>2021-02-03T07:30:03Z</dc:date>
    <item>
      <title>Notebook server spatial dataframe date from query result parsed wrong</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1022906#M245</link>
      <description>&lt;P&gt;I'm currently testing a Notebook server standard 10.8.1 and see some strange behavior on date fields in the spatial data frame.&lt;/P&gt;&lt;P&gt;I get a layer from my ArcGIS Enterprise:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_0-1612336963824.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5198i7B8C0AF24C27DAAC/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_0-1612336963824.png" alt="JoëlHempenius3_0-1612336963824.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I do a query with a geometry filter on that layer and specify the out fields&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_1-1612337009286.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5199i7D3E61BBBE9F4948/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_1-1612337009286.png" alt="JoëlHempenius3_1-1612337009286.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And from the result I get the spatial data frame:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_2-1612337102018.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5200iF22744EFBC33870F/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_2-1612337102018.png" alt="JoëlHempenius3_2-1612337102018.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Note that all dates in DATUM_AANLEG column are close to unix epoch time.&lt;/P&gt;&lt;P&gt;When I get feature with OBJECTID 17296550&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_3-1612337205274.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5201iE1B120812ABBA4EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_3-1612337205274.png" alt="JoëlHempenius3_3-1612337205274.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and I convert the date manually, (javascript console new Date(1403748000000) ) I get&amp;nbsp;Thu Jun 26 2014 04:00:00 GMT+0200 (Midden-Europese zomertijd), which is the correct date.&lt;/P&gt;&lt;P&gt;Clearly, something goes wrong when querying the service and converting the results to the spatial data frame. But I do not see where and how I can fix it.&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 07:30:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1022906#M245</guid>
      <dc:creator>JoëlHempenius3</dc:creator>
      <dc:date>2021-02-03T07:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook server spatial dataframe date from query result parsed wrong</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1022975#M246</link>
      <description>&lt;P&gt;I believe the issue here is that pandas infers timestamps to be in &lt;STRONG&gt;nanoseconds&lt;/STRONG&gt;, according to &lt;A href="https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#epoch-timestamps" target="_self"&gt;the docs&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;To address this, you'll need to explicitly tell pandas that your timestamps are in &lt;STRONG&gt;milliseconds&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Consider the following code block and its output:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;rng = np.random.default_rng()

df = pd.DataFrame({'dates':rng.integers(low=1403700000000, high=1403800000000, size=20)})

df.assign(
    nanoseconds=df['dates'].astype('datetime64[ns]'),
    milliseconds=df['dates'].astype('datetime64[ms]')    
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1612363507566.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5210iF492B0D1A957C2C2/image-size/large?v=v2&amp;amp;px=999" role="button" title="jcarlson_0-1612363507566.png" alt="jcarlson_0-1612363507566.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Looks familiar!&lt;/P&gt;&lt;P&gt;In your code, just append ".astype({'DATUM_AANLEG':'datetime64[ms]'})" after "sdf", and that should get you on the right track.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 14:45:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1022975#M246</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-02-03T14:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook server spatial dataframe date from query result parsed wrong</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1023036#M247</link>
      <description>&lt;P&gt;Hi Josh,&lt;/P&gt;&lt;P&gt;Thanks for your response.&lt;BR /&gt;I tried your suggestion this way:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_0-1612369120825.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5224iF5DF8F0BF5547ACA/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_0-1612369120825.png" alt="JoëlHempenius3_0-1612369120825.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But that didn't make any difference. I'm not sure whether I did that right.&lt;/P&gt;&lt;P&gt;I also tried this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_1-1612369317167.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5227i9ADE7703D4747C88/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_1-1612369317167.png" alt="JoëlHempenius3_1-1612369317167.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;but that doesn't fix it either.&lt;/P&gt;&lt;P&gt;And finally:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_3-1612369684178.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5229i7000F8A4CB650BF3/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_3-1612369684178.png" alt="JoëlHempenius3_3-1612369684178.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It clearly shows though that I'm new to panda's and don't know what I'm doing&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":panda_face:"&gt;🐼&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code sample looks fine on my Notebook server&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_2-1612369427777.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5228i7AFF62CC83AC0AD1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JoëlHempenius3_2-1612369427777.png" alt="JoëlHempenius3_2-1612369427777.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any other suggestions?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:29:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1023036#M247</guid>
      <dc:creator>JoëlHempenius3</dc:creator>
      <dc:date>2021-02-03T16:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook server spatial dataframe date from query result parsed wrong</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1023049#M248</link>
      <description>&lt;P&gt;That's very odd. There's something else going on, it's not just you being new to Pandas.&lt;/P&gt;&lt;P&gt;Here are some other suggestions:&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;Using "as_df=True"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;In the initial &lt;STRONG&gt;query&lt;/STRONG&gt;, include "as_df=True", rather than subsequently calling ".sdf" on the featureset. Then your query comes out directly into a dataframe. Saves you a step and an intermediate output as well, even if it doesn't solve the problem.&lt;/P&gt;&lt;P&gt;I've noticed a few differences between the two methods of generating a spatially-enabled dataframes, and I use both, depending on the situation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;Get the Integer First&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;It seems it's converting your field to a datetime64[ns] at the initial conversion to a dataframe.&lt;/P&gt;&lt;P&gt;If we're starting form a datetime instead of an integer, converting that to other datetime types would change the underlying integer value, but remain representative of the same timestamp.&lt;/P&gt;&lt;P&gt;So what we need to do is get the integer that it&amp;nbsp;&lt;EM&gt;thinks&lt;/EM&gt; are in nanoseconds, and call "astype" on&amp;nbsp;&lt;EM&gt;that&lt;/EM&gt;. It seems rather inelegant, but as long as we get the right data in the end, I suppose.&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;spdf['DATUM_AANLEG'].astype('int').astype('datetime64[ms]')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="5"&gt;Doing some Math&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;If that second suggestion doesn't work, you could try to convert your timestamps into nanosecond integers. 1 ms = 1 * 10^6 ns.&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(spdf['DATUM_AANLEG'].astype('int') * 10**6).astype('datetime64[ns]')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope at least &lt;EM&gt;one &lt;/EM&gt;of those things works!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 17:01:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1023049#M248</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-02-03T17:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook server spatial dataframe date from query result parsed wrong</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1023313#M249</link>
      <description>&lt;P&gt;I think I will contact my distributor, because "as_df" doesn't work:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_0-1612425151505.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5278i0ED29FB5E4968328/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_0-1612425151505.png" alt="JoëlHempenius3_0-1612425151505.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Your second suggestion also resulted in an exception.&lt;/P&gt;&lt;P&gt;But finally:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoëlHempenius3_1-1612425321269.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/5279i3E584F37EDA3CAAC/image-size/large?v=v2&amp;amp;px=999" role="button" title="JoëlHempenius3_1-1612425321269.png" alt="JoëlHempenius3_1-1612425321269.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Still going to contact my distributor, because it shouldn't be so difficult.&lt;/P&gt;&lt;P&gt;Thanks for all your suggestion Josh&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 07:56:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/notebook-server-spatial-dataframe-date-from-query/m-p/1023313#M249</guid>
      <dc:creator>JoëlHempenius3</dc:creator>
      <dc:date>2021-02-04T07:56:23Z</dc:date>
    </item>
  </channel>
</rss>

