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

bw2data error with config.is_test #39

Closed
cmutel opened this issue Sep 18, 2023 · 2 comments
Closed

bw2data error with config.is_test #39

cmutel opened this issue Sep 18, 2023 · 2 comments

Comments

@cmutel
Copy link
Member

cmutel commented Sep 18, 2023

Running:

import micropip
await micropip.install(
    'https://files.brightway.dev/fs-2.5.1-py2.py3-none-any.whl'
)
import os
os.environ["BRIGHTWAY_DIR"] = "/tmp/"
await micropip.install('bw2io==0.9.dev23', keep_going = True)
await micropip.install('bw2calc==2.0.dev14', keep_going = True)
await micropip.install('bw2data==4.0.dev28', keep_going = True)
import bw2data
import bw2calc
import bw2io
bw2io.add_example_database(searchable=False)

Leads to the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 bw2io.add_example_database(searchable=False)

File /lib/python3.11/site-packages/bw2io/data/__init__.py:471, in add_example_database(overwrite, searchable)
    469 importer.apply_strategies()
    470 importer.match_database(fields=["name"])
--> 471 importer.write_database(activate_parameters=True, searchable=searchable)
    473 group = "Mobility exchanges"
    474 Group.delete().where(Group.name == group).execute()

File /lib/python3.11/site-packages/bw2io/importers/excel.py:282, in ExcelImporter.write_database(self, **kwargs)
    280 """Same as base ``write_database`` method, but ``activate_parameters`` is True by default."""
    281 kwargs["activate_parameters"] = kwargs.get("activate_parameters", True)
--> 282 super(ExcelImporter, self).write_database(**kwargs)

File /lib/python3.11/site-packages/bw2io/importers/base_lci.py:278, in LCIImporter.write_database(self, data, delete_existing, backend, activate_parameters, db_name, searchable, **kwargs)
    275 self.write_database_parameters(activate_parameters, delete_existing)
    277 existing.update(data)
--> 278 db.write(existing, searchable=searchable)
    280 if activate_parameters:
    281     self._write_activity_parameters(activity_parameters)

File /lib/python3.11/site-packages/bw2data/project.py:432, in writable_project(wrapped, instance, args, kwargs)
    429 @wrapt.decorator
    430 def writable_project(wrapped, instance, args, kwargs):
    431     warnings.warn("`writable_project` is obsolete and does nothing", DeprecationWarning)
--> 432     return wrapped(*args, **kwargs)

File /lib/python3.11/site-packages/bw2data/backends/base.py:525, in SQLiteBackend.write(self, data, process, searchable)
    523 if data:
    524     try:
--> 525         self._efficient_write_many_data(data)
    526     except:
    527         # Purge all data from database, then reraise
    528         self.delete(warn=False)

File /lib/python3.11/site-packages/bw2data/backends/base.py:464, in SQLiteBackend._efficient_write_many_data(self, data, indices)
    461 self.delete(keep_params=True, warn=False, vacuum=False)
    462 exchanges, activities = [], []
--> 464 for index, (key, ds) in enumerate(tqdm_wrapper(data.items(), getattr(config, "is_test"))):
    465     exchanges, activities = self._efficient_write_dataset(
    466         index, key, ds, exchanges, activities
    467     )
    469 if activities:

AttributeError: 'Config' object has no attribute 'is_test'
@cmutel
Copy link
Member Author

cmutel commented Sep 18, 2023

This now works with a new release of bw2data. But we need to do exactly the following - note that the bw2data micropip import line now occurs earlier:

import micropip
await micropip.install(
    'https://files.brightway.dev/fs-2.5.1-py2.py3-none-any.whl'
)
import os
os.environ["BRIGHTWAY_DIR"] = "/tmp/"
await micropip.install('bw2data==4.0.dev29', keep_going = True)
await micropip.install('bw2io==0.9.dev23', keep_going = True)
await micropip.install('bw2calc==2.0.dev14', keep_going = True)
import bw2data
import bw2calc
import bw2io
bw2io.add_example_database(searchable=False)

@cmutel cmutel closed this as completed Sep 18, 2023
@michaelweinold
Copy link
Collaborator

boom-mind-blown

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