From ae66f7eef81cb35a9fcdfe789aec88f99dad3dc1 Mon Sep 17 00:00:00 2001 From: Christophe Combelles Date: Tue, 19 Sep 2023 19:35:26 +0200 Subject: [PATCH 1/7] ensure categories are tuple --- bw2io/strategies/lcia.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bw2io/strategies/lcia.py b/bw2io/strategies/lcia.py index d026f35d..bf7837b0 100644 --- a/bw2io/strategies/lcia.py +++ b/bw2io/strategies/lcia.py @@ -303,7 +303,7 @@ def add_subcategories(obj, mapping): ) for method in data: - already_have = {(obj["name"], obj["categories"]) for obj in method["exchanges"]} + already_have = {(obj["name"], tuple(obj["categories"])) for obj in method["exchanges"]} new_cfs = [] for obj in method["exchanges"]: From 9f40521ad3c34b47a1439f31d3ee750195738689 Mon Sep 17 00:00:00 2001 From: Christophe Combelles Date: Wed, 17 May 2023 15:59:14 +0200 Subject: [PATCH 2/7] Missing attribute during import (fixes #196) --- bw2io/extractors/ecospold2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bw2io/extractors/ecospold2.py b/bw2io/extractors/ecospold2.py index 9ae683b2..adc3bbb8 100644 --- a/bw2io/extractors/ecospold2.py +++ b/bw2io/extractors/ecospold2.py @@ -235,13 +235,13 @@ def extract_activity(cls, dirpath, filename, db_name): "Included activities start: ", getattr2( stem.activityDescription.activity, "includedActivitiesStart" - ).get("text"), + ) ), ( "Included activities end: ", getattr2( stem.activityDescription.activity, "includedActivitiesEnd" - ).get("text"), + ) ), ( "Geography: ", @@ -264,7 +264,7 @@ def extract_activity(cls, dirpath, filename, db_name): ] comment = "\n".join( [ - (" ".join(x) if isinstance(x, tuple) else x) + (" ".join(str(x)) if isinstance(x, tuple) else x) for x in comments if (x[1] if isinstance(x, tuple) else x) ] From f3e2e80332973818faf3279f0a454d87f468f354 Mon Sep 17 00:00:00 2001 From: Christophe Combelles Date: Sat, 18 Nov 2023 19:33:18 +0100 Subject: [PATCH 3/7] other tuple conversion --- bw2io/strategies/lcia.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bw2io/strategies/lcia.py b/bw2io/strategies/lcia.py index bf7837b0..84f15add 100644 --- a/bw2io/strategies/lcia.py +++ b/bw2io/strategies/lcia.py @@ -313,7 +313,7 @@ def add_subcategories(obj, mapping): subcat_cfs = [ x for x in add_subcategories(obj, mapping) - if (x["name"], x["categories"]) not in already_have + if (x["name"], tuple(x["categories"])) not in already_have ] if subcat_cfs and remove and not obj.get("input"): obj["remove_me"] = True From 4cda6d243f09af35831d80df8e58170638dd20de Mon Sep 17 00:00:00 2001 From: Christophe Combelles Date: Sat, 18 Nov 2023 20:47:10 +0100 Subject: [PATCH 4/7] basic test adapted from the doctest --- tests/strategies/lcia.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/strategies/lcia.py b/tests/strategies/lcia.py index 49ee4a4a..efc801d9 100644 --- a/tests/strategies/lcia.py +++ b/tests/strategies/lcia.py @@ -459,6 +459,21 @@ def test_match_subcategories_makes_copies(self): self.assertEqual(cf["amount"], 2) +def test_categories_as_list(): + """ issues/212 + """ + data = [ + { + "name": "Method 1", + "exchanges": [ + {"categories": ["air",], "name": "Emission", "unit": "kg", "amount": 1.0}, + ], + } + ] + biosphere_db_name = "example_biosphere" + match_subcategories(data, biosphere_db_name) # should pass without traceback + + def test_rationalize_method_names_no_remove_lt(): given = [ {"name": ("aw/o LT", "b", "c w/o LT")}, From 66108cfb08ee4bd626a8b8fb0454cdb61da678bb Mon Sep 17 00:00:00 2001 From: Christophe Combelles Date: Sat, 18 Nov 2023 21:16:03 +0100 Subject: [PATCH 5/7] Added a test that checks the IncludedActivitiesStart|End are present in the expected output. Also fixed the str conversion. --- bw2io/extractors/ecospold2.py | 2 +- tests/ecospold2/ecospold2_extractor.py | 6 +++--- ...-555555555555_66666666-7777-8888-9999-000000000000.spold | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bw2io/extractors/ecospold2.py b/bw2io/extractors/ecospold2.py index adc3bbb8..95f3777a 100644 --- a/bw2io/extractors/ecospold2.py +++ b/bw2io/extractors/ecospold2.py @@ -264,7 +264,7 @@ def extract_activity(cls, dirpath, filename, db_name): ] comment = "\n".join( [ - (" ".join(str(x)) if isinstance(x, tuple) else x) + (" ".join(str(i) for i in x) if isinstance(x, tuple) else x) for x in comments if (x[1] if isinstance(x, tuple) else x) ] diff --git a/tests/ecospold2/ecospold2_extractor.py b/tests/ecospold2/ecospold2_extractor.py index 18de433e..729112a5 100644 --- a/tests/ecospold2/ecospold2_extractor.py +++ b/tests/ecospold2/ecospold2_extractor.py @@ -12,7 +12,7 @@ def test_extraction_without_synonyms(): "ei", ) expected = { - "comment": "Things and stuff and whatnot\nTechnology: typical technology for ze Germans!", + "comment": "Things and stuff and whatnot\nIncluded activities start: Includes start stuff\nIncluded activities end: Includes end stuff\nTechnology: typical technology for ze Germans!", "classifications": [ ("EcoSpold01Categories", "construction materials/concrete"), ( @@ -80,7 +80,7 @@ def test_extraction_without_synonyms(): "flow": "075e433b-4be4-448e-9510-9a5029c1ce94", "type": "biosphere", "chemical formula": "h2o2", - 'formula': 'does_it_hurt_when_dropped_on_foot * 2', + "formula": "does_it_hurt_when_dropped_on_foot * 2", "variable name": "it_is_boring_to_do_this_manually", "name": "Water", "classifications": {"CPC": []}, @@ -148,7 +148,7 @@ def test_extraction_with_synonyms(): "ei", ) expected = { - "comment": "Things and stuff and whatnot\nTechnology: typical technology for ze Germans!", + "comment": "Things and stuff and whatnot\nIncluded activities end: Includes some stuff\nTechnology: typical technology for ze Germans!", "classifications": [ ("EcoSpold01Categories", "construction materials/concrete"), ( diff --git a/tests/fixtures/ecospold2/00000_11111111-2222-3333-4444-555555555555_66666666-7777-8888-9999-000000000000.spold b/tests/fixtures/ecospold2/00000_11111111-2222-3333-4444-555555555555_66666666-7777-8888-9999-000000000000.spold index 37c5c3a6..7fff5870 100644 --- a/tests/fixtures/ecospold2/00000_11111111-2222-3333-4444-555555555555_66666666-7777-8888-9999-000000000000.spold +++ b/tests/fixtures/ecospold2/00000_11111111-2222-3333-4444-555555555555_66666666-7777-8888-9999-000000000000.spold @@ -4,8 +4,8 @@ concrete block production - - Includes some stuff + Includes start stuff + Includes end stuff Things and stuff and whatnot From 85d16363200bc40bed70e24fadd1680de87437fa Mon Sep 17 00:00:00 2001 From: Michael Weinold <23102087+michaelweinold@users.noreply.github.com> Date: Sat, 2 Dec 2023 07:50:34 +0100 Subject: [PATCH 6/7] updated documentation workflow --- ...l_reusable.yml => trigger_submodule_update_reuse.yml} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename .github/workflows/{github_action_trigger_submodule_pull_reusable.yml => trigger_submodule_update_reuse.yml} (53%) diff --git a/.github/workflows/github_action_trigger_submodule_pull_reusable.yml b/.github/workflows/trigger_submodule_update_reuse.yml similarity index 53% rename from .github/workflows/github_action_trigger_submodule_pull_reusable.yml rename to .github/workflows/trigger_submodule_update_reuse.yml index 8b103b59..82d19336 100644 --- a/.github/workflows/github_action_trigger_submodule_pull_reusable.yml +++ b/.github/workflows/trigger_submodule_update_reuse.yml @@ -1,5 +1,6 @@ -# this workflow re-uses the workflow 'github_action_trigger_submodule_pull_main.yml' in the brightway-documentation repository -name: Create Workflow Dispatch (Trigger Submodule Pull), Re-Use Workflow +# This workflow re-uses the workflow 'trigger_submodule_update_main.yml' +# from the brightway-documentation repository. +name: Re-Use Workflow - Create Workflow Dispatch (Trigger Submodule Update) on: push: @@ -10,5 +11,5 @@ on: jobs: re-use_workflow: uses: - brightway-lca/brightway-documentation/.github/workflows/github_action_trigger_submodule_pull_main.yml@main - secrets: inherit # https://docs.github.com/en/actions/using-workflows/reusing-workflows#passing-secrets-to-nested-workflows \ No newline at end of file + brightway-lca/brightway-documentation/.github/workflows/trigger_submodule_update_main.yml@main + secrets: inherit # https://docs.github.com/en/actions/using-workflows/reusing-workflows#passing-secrets-to-nested-workflows From 28b9d768fa0e6212ca6c96ba550b88e46a0b5cc6 Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Mon, 4 Dec 2023 10:47:59 +0100 Subject: [PATCH 7/7] Allow additional kwargs in extractors --- bw2io/extractors/csv.py | 4 ++-- bw2io/extractors/ecospold1_lcia.py | 2 +- bw2io/extractors/excel.py | 2 +- bw2io/extractors/json_ld.py | 2 +- bw2io/extractors/simapro_csv.py | 2 +- bw2io/extractors/simapro_lcia_csv.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bw2io/extractors/csv.py b/bw2io/extractors/csv.py index 0e53fba4..c0b5ffea 100644 --- a/bw2io/extractors/csv.py +++ b/bw2io/extractors/csv.py @@ -17,7 +17,7 @@ class CSVExtractor(object): """ @classmethod - def extract(cls, filepath, encoding="utf-8-sig"): + def extract(cls, filepath, encoding="utf-8-sig", **kwargs): """ Extracts CSV file data from the filepath. @@ -47,4 +47,4 @@ def extract(cls, filepath, encoding="utf-8-sig"): with open(filepath, encoding=encoding) as f: reader = csv.reader(f) data = [row for row in reader] - return [os.path.basename(filepath), data] \ No newline at end of file + return [os.path.basename(filepath), data] diff --git a/bw2io/extractors/ecospold1_lcia.py b/bw2io/extractors/ecospold1_lcia.py index cd1cdcbb..9a5879bd 100644 --- a/bw2io/extractors/ecospold1_lcia.py +++ b/bw2io/extractors/ecospold1_lcia.py @@ -18,7 +18,7 @@ class Ecospold1LCIAExtractor(object): """ @classmethod - def extract(cls, path): + def extract(cls, path, **kwargs): """ Extracts ecospold XML file data. diff --git a/bw2io/extractors/excel.py b/bw2io/extractors/excel.py index 3c2d1b03..9ef7949b 100644 --- a/bw2io/extractors/excel.py +++ b/bw2io/extractors/excel.py @@ -79,7 +79,7 @@ class ExcelExtractor: >>> data = extractor.extract(filepath) """ @classmethod - def extract(cls, filepath: Path): + def extract(cls, filepath: Path, **kwargs): """ Extract data from an Excel file. diff --git a/bw2io/extractors/json_ld.py b/bw2io/extractors/json_ld.py index 955880d6..19c79e6a 100644 --- a/bw2io/extractors/json_ld.py +++ b/bw2io/extractors/json_ld.py @@ -22,7 +22,7 @@ class JSONLDExtractor(object): Directories to ignore when extracting JSON-LD data. """ @classmethod - def extract(cls, filepath, add_filename=True): + def extract(cls, filepath, add_filename=True, **kwargs): """ Extracts JSON-LD data from the filepath. diff --git a/bw2io/extractors/simapro_csv.py b/bw2io/extractors/simapro_csv.py index befcc7af..6a829388 100644 --- a/bw2io/extractors/simapro_csv.py +++ b/bw2io/extractors/simapro_csv.py @@ -162,7 +162,7 @@ class SimaProCSVExtractor(object): """ @classmethod - def extract(cls, filepath, delimiter=";", name=None, encoding="cp1252"): + def extract(cls, filepath, delimiter=";", name=None, encoding="cp1252", **kwargs): """ Extract data from a SimaPro export file (.csv) and returns a list of datasets, global parameters, and project metadata. diff --git a/bw2io/extractors/simapro_lcia_csv.py b/bw2io/extractors/simapro_lcia_csv.py index f8c10337..73bdc818 100644 --- a/bw2io/extractors/simapro_lcia_csv.py +++ b/bw2io/extractors/simapro_lcia_csv.py @@ -54,7 +54,7 @@ class SimaProLCIACSVExtractor(object): """ @classmethod - def extract(cls, filepath, delimiter=";", encoding="cp1252"): + def extract(cls, filepath, delimiter=";", encoding="cp1252", **kwargs): assert os.path.exists(filepath), "Can't find file %s" % filepath log, logfile = get_io_logger("SimaPro-LCIA-extractor")