USEPA / fedelemflowlist

MIT License
34 stars 21 forks source link

AttributeError: 'Ref' object has no attribute 'to_json' when calling `write_jsonld` with flowmappings #184

Closed fjuniorr closed 1 year ago

fjuniorr commented 1 year ago

I'm trying to generate openLCA JSON-LD zip archive with elementary flows and flowmappings and I'm get the error "AttributeError: 'Ref' object has no attribute 'to_json'". Here a snippet reproducing the error:

import fedelemflowlist
from pathlib import Path

output_path = Path('flows_w_mappings.zip')
flowlist = fedelemflowlist.get_flows(preferred_only=False)
flowlist = flowlist.iloc[0:100]
flowmapping = fedelemflowlist.get_flowmapping('ImpactWorld+')
fedelemflowlist.write_jsonld(flowlist,output_path, flowmapping)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/fjunior/Projects/cauldron/Federal-LCA-Commons-Elementary-Flow-List/fedelemflowlist/__init__.py", line 79, in write_jsonld
    writer.write_to(path)
  File "/Users/fjunior/Projects/cauldron/Federal-LCA-Commons-Elementary-Flow-List/fedelemflowlist/jsonld.py", line 146, in write_to
    self._write_mappings(zw)
  File "/Users/fjunior/Projects/cauldron/Federal-LCA-Commons-Elementary-Flow-List/fedelemflowlist/jsonld.py", line 224, in _write_mappings
    mappings.append(e.to_json())
                    ^^^^^^^^^^^
  File "/Users/fjunior/Projects/cauldron/Federal-LCA-Commons-Elementary-Flow-List/fedelemflowlist/jsonld.py", line 119, in to_json
    'from': self.source_flow.to_json(),
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/fjunior/Projects/cauldron/Federal-LCA-Commons-Elementary-Flow-List/fedelemflowlist/jsonld.py", line 74, in to_json
    'flow': flow_ref.to_json()
            ^^^^^^^^^^^^^^^^
AttributeError: 'Ref' object has no attribute 'to_json'

I got the same error running the the run_mappings.ipynb notebook locally[^20231118T080354].

[^20231118T080354]: I did not manage to make it work in Binder.

fjuniorr commented 12 months ago

Thanks!