Skip to content

Commit

Permalink
Merge pull request #2 from TimoDiepers/main
Browse files Browse the repository at this point in the history
Python 3.12 compatibility
  • Loading branch information
romainsacchi authored Apr 12, 2024
2 parents f0a0f46 + 530ad9a commit aa5b98a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion polyviz/choro.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from bw2data.backends import Activity as BW25Activity
except ImportError:
BW25Activity = None

valid_types = tuple(filter(None, (PeeweeActivity, BW25Activity)))



def choro(
Expand Down Expand Up @@ -47,7 +50,7 @@ def choro(

assert isinstance(method, tuple), "`method` should be a tuple."
assert isinstance(
activity, (PeeweeActivity, BW25Activity)
activity, valid_types
), "`activity` should be a brightway2 activity."

# fetch unit of method
Expand Down
4 changes: 3 additions & 1 deletion polyviz/treemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
except ImportError:
BW25Activity = None

valid_types = tuple(filter(None, (PeeweeActivity, BW25Activity)))


def treemap(
activity: Union[PeeweeActivity, BW25Activity],
Expand Down Expand Up @@ -47,7 +49,7 @@ def treemap(

assert isinstance(method, tuple), "`method` should be a tuple."
assert isinstance(
activity, (PeeweeActivity, BW25Activity)
activity, valid_types
), "`activity` should be a brightway2 activity."

# fetch unit of method
Expand Down
8 changes: 5 additions & 3 deletions polyviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
except ImportError:
BW25Activity = None

valid_types = tuple(filter(None, (PeeweeActivity, BW25Activity)))


def calculate_supply_chain(
activity: Union[PeeweeActivity, BW25Activity],
Expand All @@ -41,7 +43,7 @@ def calculate_supply_chain(
"""

assert isinstance(
activity, (PeeweeActivity, BW25Activity)
activity, valid_types
), "`activity` should be a brightway2 activity."

amount = -1 if identify_waste_process(activity) else 1
Expand Down Expand Up @@ -76,7 +78,7 @@ def calculate_lcia_score(
:return: LCIA score, C matrix, and reverse dictionary
"""
assert isinstance(
activity, (PeeweeActivity, BW25Activity)
activity, valid_types
), "`activity` should be a brightway2 activity."

print("Calculating LCIA score...")
Expand Down Expand Up @@ -117,7 +119,7 @@ def identify_waste_process(activity: Union[PeeweeActivity, BW25Activity]) -> boo


def get_geo_distribution_of_impacts_for_choro_graph(
activity: (PeeweeActivity, BW25Activity),
activity: Union[PeeweeActivity, BW25Activity],
method: tuple,
cutoff: float = 0.0001,
) -> pd.DataFrame:
Expand Down
4 changes: 3 additions & 1 deletion polyviz/violin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
except ImportError:
BW25Activity = None

valid_types = tuple(filter(None, (PeeweeActivity, BW25Activity)))


def violin(
activities: list,
Expand All @@ -45,7 +47,7 @@ def violin(

for act in activities:
assert isinstance(
act, Union[PeeweeActivity, BW25Activity]
act, valid_types
), "`activity` should be a brightway2 activity."

def make_name(activities):
Expand Down

0 comments on commit aa5b98a

Please sign in to comment.