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

Fix compatibility with python 3.8 and 3.9 #245

Merged
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
12 changes: 6 additions & 6 deletions bw2io/ecoinvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import zipfile
from collections import defaultdict
from pathlib import Path
from typing import Any
from typing import Any, Optional, List

import bw2data as bd
import ecoinvent_interface as ei
Expand All @@ -23,7 +23,7 @@
USE_MP = True


def get_excel_sheet_names(file_path: Path) -> list[str]:
def get_excel_sheet_names(file_path: Path) -> List[str]:
"""Read XML metadata file instead of using openpyxl, which loads the whole workbook.

From https://stackoverflow.com/questions/12250024/how-to-obtain-sheet-names-from-xls-files-without-loading-the-whole-file.
Expand All @@ -36,7 +36,7 @@ def get_excel_sheet_names(file_path: Path) -> list[str]:
return sheets


def header_dict(array: list) -> list[dict]:
def header_dict(array: list) -> List[dict]:
return [
{header.lower(): value for header, value in zip(array[0], row)}
for row in array[1:]
Expand All @@ -62,11 +62,11 @@ def pick_a_unit_label_already(obj: dict) -> str:
def import_ecoinvent_release(
version: str,
system_model: str,
username: str | None = None,
password: str | None = None,
username: Optional[str] = None,
password: Optional[str] = None,
lci: bool = True,
lcia: bool = True,
biosphere_name: str | None = None,
biosphere_name: Optional[str] = None,
biosphere_write_mode: str = "patch",
importer_signal: Any = None,
use_mp: bool = USE_MP,
Expand Down
3 changes: 2 additions & 1 deletion bw2io/importers/ecoinvent_lcia.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import warnings
from numbers import Number
from typing import Optional

from bw2data import Database, config

Expand All @@ -22,7 +23,7 @@ class EcoinventLCIAImporter(LCIAImporter):

"""

def __init__(self, biosphere_database: str | None = None):
def __init__(self, biosphere_database: Optional[str] = None):
"""Initialize an instance of EcoinventLCIAImporter.

Defines strategies in ``__init__`` because ``config.biosphere`` is dynamic.
Expand Down
6 changes: 3 additions & 3 deletions bw2io/importers/ecospold2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from functools import partial
from pathlib import Path
from time import time
from typing import Any
from typing import Any, Optional
import os

from bw2data import Database, config
Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(
self,
dirpath: str,
db_name: str,
biosphere_database_name: str | None = None,
biosphere_database_name: Optional[str] = None,
extractor: Any=Ecospold2DataExtractor,
use_mp: bool=USE_MP,
signal: Any=None,
Expand All @@ -76,7 +76,7 @@ def __init__(
Path to the directory containing the ecospold2 file.
db_name : str
Name of the LCI database.
biosphere_database_name : str | None
biosphere_database_name : Union[str, None]
Name of biosphere database to link to. Uses `config.biosphere` if not provided.
extractor : class
Class for extracting data from the ecospold2 file, by default Ecospold2DataExtractor.
Expand Down
5 changes: 3 additions & 2 deletions bw2io/importers/ecospold2_biosphere.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Optional

from lxml import objectify

Expand Down Expand Up @@ -44,7 +45,7 @@ def __init__(
self,
name: str = "biosphere3",
version: str = "3.9",
filepath: Path | None = None,
filepath: Optional[Path] = None,
):
"""
Initialize the importer.
Expand All @@ -64,7 +65,7 @@ def __init__(
ensure_categories_are_tuples,
]

def extract(self, version: str | None, filepath: Path | None):
def extract(self, version: Optional[str], filepath: Optional[Path]) :
"""
Extract elementary flows from the xml file.

Expand Down
3 changes: 2 additions & 1 deletion bw2io/strategies/ecospold2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
import warnings
from typing import List, Dict

from bw2data import Database
from bw2data.logs import close_log, get_io_logger
Expand All @@ -9,7 +10,7 @@
from .migrations import migrate_exchanges, migrations


def link_biosphere_by_flow_uuid(db: list[dict], biosphere: str="biosphere3"):
def link_biosphere_by_flow_uuid(db: List[Dict], biosphere: str="biosphere3"):
"""
Link the exchanges in the given list of datasets to the specified
biosphere database by flow UUID.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
author="Chris Mutel",
author_email="[email protected]",
license="BSD 3-clause",
python_requires='>=3.8',
install_requires=REQUIREMENTS,
url="https://github.com/brightway-lca/brightway2-io",
long_description=open("README.rst").read(),
Expand All @@ -51,7 +52,6 @@
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Scientific/Engineering :: Mathematics",
Expand Down