cmutel/regionalized-lca-examples

bwr.create_world_collections(): Object of type WindowsPath is not JSON serializable

Closed this issue · 1 comments

I get the following error when running the LC-IMPACT-case study, "bwr.create_world_collections()"

TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_944/1582787872.py in
----> 1 bwr.create_world_collections()

~\Miniconda3\envs\bw25reg\lib\site-packages\bw2regional\base_data.py in create_world_collections()
254 def create_world_collections():
255 print("Downloading and creating 'world' geocollection with countries")
--> 256 geocollections["world"] = {
257 "filepath": download_file(
258 "countries.gpkg", "regional", url="https://geography.ecoinvent.org/files/"

~\Miniconda3\envs\bw25reg\lib\site-packages\bw2regional\meta.py in setitem(self, key, value)
32 value["sha256"] = sha256(value["filepath"])
33 value["kind"] = get_spatial_dataset_kind(value["filepath"])
---> 34 super(Geocollections, self).setitem(key, value)
35
36

~\Miniconda3\envs\bw25reg\lib\site-packages\bw2data\project.py in writable_project(wrapped, instance, args, kwargs)
444 if projects.read_only:
445 raise ReadOnlyProject(READ_ONLY_PROJECT)
--> 446 return wrapped(*args, **kwargs)

~\Miniconda3\envs\bw25reg\lib\site-packages\bw2data\serialization.py in setitem(self, key, value)
135 def setitem(self, key, value):
136 self.data[key] = value
--> 137 self.flush()
138
139 def contains(self, key):

~\Miniconda3\envs\bw25reg\lib\site-packages\bw2data\serialization.py in flush(self)
120 def flush(self):
121 """Serialize the current data to disk."""
--> 122 self.serialize()
123
124 @Property

~\Miniconda3\envs\bw25reg\lib\site-packages\bw2data\project.py in writable_project(wrapped, instance, args, kwargs)
444 if projects.read_only:
445 raise ReadOnlyProject(READ_ONLY_PROJECT)
--> 446 return wrapped(*args, **kwargs)

~\Miniconda3\envs\bw25reg\lib\site-packages\bw2data\serialization.py in serialize(self, filepath)
189 """
190 with atomic_open(filepath or self.filepath, "w") as f:
--> 191 f.write(JsonWrapper.dumps(self.pack(self.data)))
192
193 def deserialize(self):

~\Miniconda3\envs\bw25reg\lib\site-packages\bw2data\serialization.py in dumps(self, data)
50 return anyjson.serialize(data)
51 else:
---> 52 return json.dumps(data)
53
54 @classmethod

~\Miniconda3\envs\bw25reg\lib\json_init_.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder

~\Miniconda3\envs\bw25reg\lib\json\encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)

~\Miniconda3\envs\bw25reg\lib\json\encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,

~\Miniconda3\envs\bw25reg\lib\json\encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(f'Object of type {o.class.name} '
180 f'is not JSON serializable')
181

TypeError: Object of type WindowsPath is not JSON serializable

Just needed to call str() on the filepath.