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

Python 3.12 compatibility #2

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading