<?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: Select rows that have invalid domain values using ArcPy in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186280#M56523</link>
    <description>&lt;P&gt;Thanks &lt;SPAN&gt;Johannes&lt;/SPAN&gt;! That's great!&lt;BR /&gt;I would have struggled with this for a week or more if I'd done it all on my own, lol.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Here's where I'm at:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Test #1:&lt;/STRONG&gt; (using my work computer; enterprise GDB)&lt;/P&gt;&lt;P&gt;I tried running the script, but got an error:&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;Error:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 41, in &amp;lt;module&amp;gt;&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 15, in check_domain_values&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 15, in &amp;lt;dictcomp&amp;gt;&lt;BR /&gt;&lt;STRONG&gt;AttributeError: 'NoneType' object has no attribute 'keys'&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bud_0-1656132373203.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/44429iC419608268C345A1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Bud_0-1656132373203.png" alt="Bud_0-1656132373203.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The table (non-spatial) has a subtype. Not sure if that's relevant or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 25 Jun 2022 05:23:15 GMT</pubDate>
    <dc:creator>Bud</dc:creator>
    <dc:date>2022-06-25T05:23:15Z</dc:date>
    <item>
      <title>Select rows that have invalid domain values using ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186065#M56508</link>
      <description>&lt;P&gt;&lt;EM&gt;ArcGIS Pro 2.6.8; Oracle 18c 10.7.1 EGDB:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;For a FC/table that has values that don't match its domains:&lt;/P&gt;&lt;P&gt;Is there a way to select all rows in the attribute table that have invalid coded-value domain values — using ArcPy?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For each row, for each field, if the field has a domain, and if the value doesn’t match the domain, then select the row.&lt;/LI&gt;&lt;LI&gt;Hopefully, the script could be dynamic, rather than needing to hardcode a list of fields with domains in the script.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt; &lt;EM&gt;(this edit was added &lt;U&gt;after&lt;/U&gt;&amp;nbsp;JohannesLindner kindly provided a script)&lt;/EM&gt;:&lt;BR /&gt;&lt;U&gt;The table has a subtype.&lt;BR /&gt;&lt;BR /&gt;&lt;/U&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;EM&gt;(I'm not great with ArcPy yet. So I thought I'd ask, in case anyone has a sample script they can share to get me started.)&lt;/EM&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;I'm aware ArcGIS Pro has "Select Only Invalid Objects" functionality in the attribute &lt;U&gt;&lt;STRONG&gt;pane&lt;/STRONG&gt;&lt;/U&gt; (not to be confused with the attribute window):&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/editing/edit-feature-attributes.htm#ESRI_SECTION1_8F13A8C397F349C9BF97D3DF2353E69F" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/help/editing/edit-feature-attributes.htm#ESRI_SECTION1_8F13A8C397F349C9BF97D3DF2353E69F&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/prevent-non-domain-values-from-being-used-across/idc-p/1186044/highlight/true#M20037" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-pro-ideas/prevent-non-domain-values-from-being-used-across/idc-p/1186044/highlight/true#M20037&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bud_0-1656083774739.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/44318iB59F26A6CA840A70/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bud_0-1656083774739.png" alt="Bud_0-1656083774739.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But that functionality doesn't work for non-spatial tables in ArcGIS Pro 2.6.8 (it only works on FCs)...that functionality was added alter in Pro 2.8.&lt;/P&gt;&lt;P&gt;Regardless, I'm wondering if ArcPy might be a better choice, when it comes to validating an entire table.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2022 05:21:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186065#M56508</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-06-25T05:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that have invalid domain values using ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186130#M56511</link>
      <description>&lt;P&gt;Huh, I would have guessed that it's easier in Python than in Arcade, but it certainly took longer to write...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Same setup as in your Arcade question (&lt;A href="https://community.esri.com/t5/attribute-rules-questions/flag-row-if-any-field-has-invalid-domain-values/m-p/1185966" target="_blank" rel="noopener"&gt;Flag row if any field has invalid domain values - Esri Community&lt;/A&gt;).&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 pathlib

def check_domain_values(in_features, flag_field, database=None):
    """sets the flag field to 0 if at least 1 field value is not in the field's domain, else 1

    in_features: str, path to the feature class or table
    flag_field: str, name of the field that has the flag
    database: str, path to the database. defaults to the parent directory of the feature class, should be set when the fc is in a feature dataset.

    """
    if database is None:
        database = pathlib.Path(in_features).parent
    
    domains = arcpy.da.ListDomains(database)
    domain_values = {d.name: list(d.codedValues.keys()) for d in domains}
    print(f"domain_values: {domain_values}\n")

    fields = arcpy.ListFields(in_features)
    allowed_values = {f.name: domain_values[f.domain] for f in fields if f.domain not in ["", None]}
    fields_with_domains = list(allowed_values.keys())
    print(f"allowed values: {allowed_values}\n")
    print(f"domain fields: {fields_with_domains}\n")
    
    fields = fields_with_domains + [flag_field]
    with arcpy.da.UpdateCursor(in_features, fields) as cursor:
        for row in cursor:
            ok = True
            for i, value in enumerate(row):
                try:
                    field = fields[i]
                    if value not in allowed_values[field]:
                        ok = False
                        break
                except KeyError: # flag_field is not in the dictionary
                    pass
            new_row = list(row)
            new_row[-1] = ok
            cursor.updateRow(new_row)&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc = arcpy.Describe("TestPoints").catalogPath
check_domain_values(fc, "IntegerField")&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;PRE&gt;domain_values: {'MyDomain': ['Value 1', 'Value 2', 'Value 3']}

allowed values: {'TextField': ['Value 1', 'Value 2', 'Value 3']}

domain fields: ['TextField']&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1656089151059.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/44336i59181990E9C0E525/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1656089151059.png" alt="JohannesLindner_0-1656089151059.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 16:48:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186130#M56511</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-24T16:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that have invalid domain values using ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186141#M56513</link>
      <description>&lt;P&gt;this will raise exceptions in at least these scenarios:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;you input a shapefile&lt;/LI&gt;&lt;LI&gt;you input a flag_field that is not Integer&lt;/LI&gt;&lt;LI&gt;probably when you have range domains in your database&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 24 Jun 2022 16:53:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186141#M56513</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-24T16:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that have invalid domain values using ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186280#M56523</link>
      <description>&lt;P&gt;Thanks &lt;SPAN&gt;Johannes&lt;/SPAN&gt;! That's great!&lt;BR /&gt;I would have struggled with this for a week or more if I'd done it all on my own, lol.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Here's where I'm at:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Test #1:&lt;/STRONG&gt; (using my work computer; enterprise GDB)&lt;/P&gt;&lt;P&gt;I tried running the script, but got an error:&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;Error:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 41, in &amp;lt;module&amp;gt;&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 15, in check_domain_values&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 15, in &amp;lt;dictcomp&amp;gt;&lt;BR /&gt;&lt;STRONG&gt;AttributeError: 'NoneType' object has no attribute 'keys'&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bud_0-1656132373203.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/44429iC419608268C345A1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Bud_0-1656132373203.png" alt="Bud_0-1656132373203.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The table (non-spatial) has a subtype. Not sure if that's relevant or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2022 05:23:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186280#M56523</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-06-25T05:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that have invalid domain values using ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186395#M56535</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Test #2:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I did a test using&amp;nbsp;ArcGIS Pro on my home computer:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ArcGIS Pro 2.9.2&lt;/LI&gt;&lt;LI&gt;FGDB&lt;/LI&gt;&lt;LI&gt;Created a non-spatial table from scratch&lt;/LI&gt;&lt;LI&gt;No subtypes&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The script &lt;STRONG&gt;worked fine&lt;/STRONG&gt;&amp;nbsp;using the specs mentioned above. So I guess there's something in my work environment that is causing a problem. I'll do some more tests...&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bud_0-1656128399854.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/44426iB7408161A066CC04/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bud_0-1656128399854.png" alt="Bud_0-1656128399854.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2022 04:48:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186395#M56535</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-06-25T04:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that have invalid domain values using ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186398#M56537</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Test #3:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I did a third test (again, on my home computer) where I tested a subtype.&lt;/P&gt;&lt;P&gt;The script ran without errors, but it didn't catch the invalid domain value. But that's totally reasonable, since I forgot to mention in my original post that the data uses a subtype...the script likely wasn't designed with subtypes in mind.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bud_1-1656130338220.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/44427i1D9AEAE0EF3F9554/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bud_1-1656130338220.png" alt="Bud_1-1656130338220.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So, to me, that suggests that the error I got in my first test (work computer) might &lt;U&gt;&lt;EM&gt;not&lt;/EM&gt;&lt;/U&gt; be caused by the subtype, since the script ran without errors on my home computer where a subtype was present.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2022 04:28:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186398#M56537</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-06-25T04:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that have invalid domain values using ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186400#M56538</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Test #4:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I did a fourth test, this time on my work computer.&lt;/P&gt;&lt;P&gt;I emailed the FGDB from my home computer to my work computer. And tested the script on the FGDB on my work computer.&lt;/P&gt;&lt;P&gt;The script ran without errors. (Although it still doesn't catch the invalid value. But as mentioned, that's expected, since the script wasn't designed for subtypes.)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bud_0-1656131168313.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/44428i0E1216DCD8DDD23C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bud_0-1656131168313.png" alt="Bud_0-1656131168313.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So that test confirms that the subtype isn't causing the error on my work computer. It also confirms that the older version of ArcGIS Pro (2.6.8) isn't causing the problem either.&lt;/P&gt;&lt;P&gt;So I think the issue must be something to do with my enterprise GDB environment (or the table).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I googled the error message:&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.google.com/search?q=%22AttributeError%3A+%27NoneType%27+object+has+no+attribute+%27keys%27%22&amp;amp;rlz=1C1GCEA_enCA990CA990&amp;amp;oq=%22AttributeError%3A+%27NoneType%27+object+has+no+attribute+%27keys%27%22&amp;amp;aqs=chrome..69i57.1104j0j7&amp;amp;sourceid=chrome&amp;amp;ie=UTF-8" target="_self"&gt;"AttributeError: 'NoneType' object has no attribute 'keys'"&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I'll review those results and see if I can figure out what's happening.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2022 04:53:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186400#M56538</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-06-25T04:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows that have invalid domain values using ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186412#M56539</link>
      <description>&lt;P&gt;It's line 15 of my code. It found at least 1 domain, but one of the domains' codedValue attribute is null.&amp;nbsp;This might be a ranged domain.&lt;/P&gt;&lt;P&gt;You could try replacing line 15 with this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;domain_values = dict()
for d in domains:
    try:
        domain_values[d.name] = list(d.codedValues.keys())
    except AttributeError:
        print(f"{d.name} is not a coded value domain.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2022 12:40:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/select-rows-that-have-invalid-domain-values-using/m-p/1186412#M56539</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-25T12:40:15Z</dc:date>
    </item>
  </channel>
</rss>

