Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: unhashable type: 'dict' #47

Open
jcbridwe opened this issue Aug 30, 2018 · 9 comments
Open

TypeError: unhashable type: 'dict' #47

jcbridwe opened this issue Aug 30, 2018 · 9 comments

Comments

@jcbridwe
Copy link

I have a simple shapefile I am trying to load into the MetadataEditor:

shp = "<C:/<...>/feature.shp"
metadata = md.MetadataEditor(shp)

When I run this, I get the following error:

TypeError: unhashable type: 'dict'

Any suggestions as to how to resolve this?

@nickrsan
Copy link
Member

nickrsan commented Aug 30, 2018

Hi there - thanks for the report. Could you provide the full traceback you're experiencing? Without knowing what line that error is occurring on and the path being followed, it's hard to know what's occurring.

Also, if possible, could you share the complete, unabbreviated code snippet you're using? Just the part that references the shapefile path and the metadata editor setup is fine, but looking to see the full path as defined in the code

@jcbridwe
Copy link
Author

Traceback (most recent call last):

File "", line 2, in
metadata = md.MetadataEditor(item)

File "C:\Users\jbridwell\AppData\Local\Continuum\anaconda3\envs\acrpro\lib\site-packages\arcpy_metadata\metadata_editor.py", line 203, in init
if elements[name] in self.dict.keys():

TypeError: unhashable type: 'dict'

@jcbridwe
Copy link
Author

Code snippet:
import arcpy, os, sys,env import arcpy_metadata as md myfeatures = "C:/Workspace/Sandbox/MetadataProject/data/model_domains" arc.env.workspace = myfeatures list = arcpy.ListFeatureClasses() for item in list: metadata = md.MetadataEditor(item)

Note: I've also tried using just:
metadata = md.MetadataEditor("C:/Workspace/Sandbox/MetadataProject/data/model_domains/pluvial.shp")

@nickrsan
Copy link
Member

Thanks - that's helpful. From your traceback, it looks like you're running this on ArcGIS Pro? Unfortunately, that's not supported yet, and I suspect it's the root cause of the message you're getting - until recently they haven't had the tools needed to export metadata to a format we could read. We haven't yet done the work needed to make sure it works in Python 3 or ArcGIS Pro.

As far as solving the general case, it seems like maybe we could add some sort of alert when loaded in Python 3 that this is the case though, to prevent unknown issues like yours.

Are you able to run it using a copy of ArcMap in the meantime? Sorry that this is the best option we have right now!

@jcbridwe
Copy link
Author

Hey thanks Nick. Trying now in my Python 2.7 env with ArcMap. I'll comment again if I get it running.

@jcbridwe
Copy link
Author

Hey Nick - I was able to get it to work in my 2.7 environment, but I have a follow up question. I was able to create an object/variable like this:
metadata = md.MetadataEditor("T:/CCSI/TECH/FEMA/2018_SO4_Innovation/MS_East/FINAL/DELIVERABLES/3_Spatial_Files/model_domains/fluvial.shp")
and then look at the metadata already in that object like this:

metadata.title
metadata.abstract

This returned the title and abstract, I guess from the .shp.xml file?
However,when I tried to change or add new metadata, I couldn't seem to find where the change was taking place. I want to change the metadata title from 'fluvial' to 'Fluvial 2D Domains', so I used:
metadata.title = "Fluvial 2D Domains"
I went into ArcCatalog and looked at the item Description and also launched the .xml file, but I did not see the title changed. Am I looking in the right place? Do I need to physically create a new .xml file?

@nickrsan
Copy link
Member

Hi - glad it worked in 2.7! I suspect since you didn't mention it and based on the symptoms that you're not calling metadata.finish() after setting the properties, which is required to write the changes back out to the file. metadata.save() is also fine, but metadata.finish() does some cleanup as well, when necessary. Are you already doing that and still not seeing changes?

@nickrsan
Copy link
Member

Another note for myself, looking at the docs, is that it might still be worth a complete example at the top that includes loading, reading data, and saving data, before showing all of the other capabilities. I think that was lost when the docs were refactored to be more complete.

@jcbridwe
Copy link
Author

Yep. That was the issue! It's working great now. I have it iterating through about 1200 files now creating metadata. Works great. I did post an additional question about adding spatial reference and bounding box metadata. Let me know if that's possible. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants