<?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 Query function throwing key error for field that is not called in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-function-throwing-key-error-for-field-that/m-p/1317716#M8922</link>
    <description>&lt;P&gt;So I'm not understanding an error I'm getting.&lt;/P&gt;&lt;P&gt;I've had the following where statement work just fine in my testing: 'Season = 2022 and Day_of_Season = 179'&lt;/P&gt;&lt;P&gt;However, when I took off the second condition it is throwing a KeyError for a field I'm not even querying. It really makes no sense. It is the only date field, but why would it work with one where statement but not the other?&lt;/P&gt;&lt;P&gt;It does work without the out_field parameter with both where statements, but it isn't included so why is it even doing anything with Hunt_Date?&lt;/P&gt;&lt;P&gt;That line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df_db = self.db.query(where='Season = 2022', out_fields=['Mallard', 'Green_winged_Teal', 'American_Wigeon', 'Northern_Pintail', 'Northern_Shoveler', 'Gadwall', 'Wood_Duck', 'Cinnamon_Blue_winged_Teal', 'Eurasian_Wigeon', 'Ring_necked_Duck', 'Canvasback', 'Bufflehead', 'Scaup_Species', 'Goldeneye_Species', 'Ruddy_Duck', 'Redhead', 'Hooded_Merganser', 'Common_Merganser', 'Scoter_Species', 'Long_tailed_Duck', 'Other_Duck_Species', 'Lesser_Snow_Goose', 'Ring_necked_Pheasant', 'California_Quail', 'Dove', 'Coot', 'Snipe', 'Hunt_Unit', 'Major_Unit', 'Day_of_Season'], as_df=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\indexes\base.py", line 3629, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Hunt_Date'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\arcgis\features\layer.py", line 4286, in query
    df[fld] / 1000, infer_datetime_format=True, unit="s"
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\frame.py", line 3505, in __getitem__
    indexer = self.columns.get_loc(key)
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\indexes\base.py", line 3631, in get_loc
    raise KeyError(key) from err
KeyError: 'Hunt_Date'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\indexes\base.py", line 3629, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Hunt_Date'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\indexes\base.py", line 3631, in get_loc
    raise KeyError(key) from err
KeyError: 'Hunt_Date'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Aug 2023 22:34:18 GMT</pubDate>
    <dc:creator>ccowin_odfw</dc:creator>
    <dc:date>2023-08-10T22:34:18Z</dc:date>
    <item>
      <title>Query function throwing key error for field that is not called</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/query-function-throwing-key-error-for-field-that/m-p/1317716#M8922</link>
      <description>&lt;P&gt;So I'm not understanding an error I'm getting.&lt;/P&gt;&lt;P&gt;I've had the following where statement work just fine in my testing: 'Season = 2022 and Day_of_Season = 179'&lt;/P&gt;&lt;P&gt;However, when I took off the second condition it is throwing a KeyError for a field I'm not even querying. It really makes no sense. It is the only date field, but why would it work with one where statement but not the other?&lt;/P&gt;&lt;P&gt;It does work without the out_field parameter with both where statements, but it isn't included so why is it even doing anything with Hunt_Date?&lt;/P&gt;&lt;P&gt;That line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df_db = self.db.query(where='Season = 2022', out_fields=['Mallard', 'Green_winged_Teal', 'American_Wigeon', 'Northern_Pintail', 'Northern_Shoveler', 'Gadwall', 'Wood_Duck', 'Cinnamon_Blue_winged_Teal', 'Eurasian_Wigeon', 'Ring_necked_Duck', 'Canvasback', 'Bufflehead', 'Scaup_Species', 'Goldeneye_Species', 'Ruddy_Duck', 'Redhead', 'Hooded_Merganser', 'Common_Merganser', 'Scoter_Species', 'Long_tailed_Duck', 'Other_Duck_Species', 'Lesser_Snow_Goose', 'Ring_necked_Pheasant', 'California_Quail', 'Dove', 'Coot', 'Snipe', 'Hunt_Unit', 'Major_Unit', 'Day_of_Season'], as_df=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\indexes\base.py", line 3629, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Hunt_Date'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\arcgis\features\layer.py", line 4286, in query
    df[fld] / 1000, infer_datetime_format=True, unit="s"
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\frame.py", line 3505, in __getitem__
    indexer = self.columns.get_loc(key)
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\indexes\base.py", line 3631, in get_loc
    raise KeyError(key) from err
KeyError: 'Hunt_Date'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\indexes\base.py", line 3629, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Hunt_Date'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:\Users\cowinch\AppData\Local\ESRI\conda\envs\arcgispro-py3-cowin\lib\site-packages\pandas\core\indexes\base.py", line 3631, in get_loc
    raise KeyError(key) from err
KeyError: 'Hunt_Date'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 22:34:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/query-function-throwing-key-error-for-field-that/m-p/1317716#M8922</guid>
      <dc:creator>ccowin_odfw</dc:creator>
      <dc:date>2023-08-10T22:34:18Z</dc:date>
    </item>
  </channel>
</rss>

