diff --git a/.github/workflows/pip-audit.yml b/.github/workflows/pip-audit.yml index 1152f470..a0fc87c1 100644 --- a/.github/workflows/pip-audit.yml +++ b/.github/workflows/pip-audit.yml @@ -26,4 +26,4 @@ jobs: - name: Install run: python -m pip install . - name: Run pip-audit - uses: pypa/gh-action-pip-audit@v1.0.3 + uses: pypa/gh-action-pip-audit@ww/pin-requests diff --git a/ITR/data/base_providers.py b/ITR/data/base_providers.py index 3e441e93..3778544d 100644 --- a/ITR/data/base_providers.py +++ b/ITR/data/base_providers.py @@ -774,9 +774,9 @@ def _extract_historic_df(self, companies: List[ICompanyData]) -> pd.DataFrame: raise ValueError("No historic data anywhere") df = pd.DataFrame.from_records(data).set_index( [ColumnsConfig.COMPANY_ID, ColumnsConfig.VARIABLE, ColumnsConfig.SCOPE]) + # Note that the first valid index may well be Quantity with a NaN value--that's fine # We just need to fill in the pure NaNs that arise from very ragged data - with warnings.catch_warnings(): # TODO: need to investigate whether there is a more sane way to avoid unit warnings warnings.simplefilter("ignore") @@ -815,6 +815,8 @@ def _historic_ei_to_dicts(self, id: str, intensities_scopes: IHistoricEIScopes) def _compute_missing_historic_ei(self, companies: List[ICompanyData], historic_df: pd.DataFrame): scopes = [EScope[scope_name] for scope_name in EScope.get_scopes()] missing_data = [] + # https://github.com/pandas-dev/pandas/issues/53053 + index_names = historic_df.index.names for company in companies: # Create keys to index historic_df DataFrame for readability production_key = (company.company_id, VariablesConfig.PRODUCTIONS, 'Production') @@ -839,6 +841,8 @@ def _compute_missing_historic_ei(self, companies: List[ICompanyData], historic_d # This only happens if ALL scope data is missing. If ANY scope data is present, we'll work with what we get. if this_missing_data and append_this_missing_data: missing_data.extend(this_missing_data) + # https://github.com/pandas-dev/pandas/issues/53053 + historic_df.index.names = index_names if missing_data: error_message = f"Provide either historic emissions intensity data, or historic emission and " \ f"production data for these company - scope combinations: {missing_data}" diff --git a/README.md b/README.md index 8ec59822..01f11659 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,13 @@ This Python module implements the ITR methodology. ## Getting started with the user interface: -If you use Anaconda environments, open an Anaconda prompt window, navigate to the 'examples' directory and run: +If you use Anaconda environments, open an Anaconda prompt window, navigate to the root of the ITR release (ITR-develop) and run: ``` conda env create -f environment.yml conda activate itr_ui -python ITR_UI.py ``` -For virtual environments, open a command prompt/terminal window, navigate to the 'examples' directory and run: +For virtual environments, open a command prompt/terminal window, navigate to the root of the ITR release and run ``` python3 -m venv itr_ui ``` @@ -25,9 +24,17 @@ Next, run: ``` python3 -m pip install --upgrade pip pip install -r requirements.txt +pip install -e . +``` + +Now you are ready to change to the examples directory and run the tool: +``` +cd examples python3 ITR_UI.py +python3 ITR_UI.py "data/20230106 ITR V2 Sample Data.xlsx" ``` -Note the python commands are ```python``` for windows and ``python3`` for linux/mac. + +Note the python commands are ```python``` for windows and ``python3`` for linux/mac. If no file is specified, the tool uses a default, small ITR dataset. With a filename given, the ITR tool will load data from that dataset. The 20230106 data template has over 120 companies across nearly a dozen sectors. Finally, open a browser window and navigate to `http://127.0.0.1:8050/` to access the user interface. diff --git a/examples/data/20220927 ITR Tool Sample Data.xlsx b/examples/data/20220927 ITR Tool Sample Data.xlsx index 0646c372..efb27b6f 100644 Binary files a/examples/data/20220927 ITR Tool Sample Data.xlsx and b/examples/data/20220927 ITR Tool Sample Data.xlsx differ diff --git a/examples/data/20220927 ITR V2 Sample Data.xlsx b/examples/data/20220927 ITR V2 Sample Data.xlsx index 3d18d918..1a3e8fb6 100644 Binary files a/examples/data/20220927 ITR V2 Sample Data.xlsx and b/examples/data/20220927 ITR V2 Sample Data.xlsx differ diff --git a/examples/data/20230106 ITR V2 Sample Data.xlsx b/examples/data/20230106 ITR V2 Sample Data.xlsx index 45f83fdf..22a05a01 100644 Binary files a/examples/data/20230106 ITR V2 Sample Data.xlsx and b/examples/data/20230106 ITR V2 Sample Data.xlsx differ diff --git a/requirements.txt b/requirements.txt index d756c003..2c83da2d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,24 +1,25 @@ -python-dotenv==0.21.0 -dash==2.7.1 -dash_bootstrap_components==1.2.1 +python-dotenv==1.0.0 +dash==2.9.3 +dash_bootstrap_components==1.4.1 multiprocess==0.70.14 -diskcache==5.4.0 +diskcache==5.6.1 iam-units==2022.10.27 jupyter==1.0.0 -matplotlib==3.6.1 +matplotlib==3.7.1 +multiprocess==0.70.14 osc-ingest-tools==0.4.3 openpyxl==3.0.10 -openscm-units==0.5.0 +openscm-units==0.5.1 pandas==1.5.3 Pint==0.20.1 Pint-Pandas==0.3 -pydantic==1.10.2 +pydantic==1.10.7 pygithub==1.55 -pytest==7.2.0 +pytest==7.3.1 Sphinx==5.1.1 sphinx-autoapi==1.9.0 sphinx-autodoc-typehints==1.19.1 sphinx-rtd-theme==1.0.0 -SQLAlchemy==1.4.42 -trino==0.322.0 +SQLAlchemy==1.4.48 +trino==0.323.0 xlrd==2.0.1