From b5869498a672ca30a722ab0859b6383b70477e0c Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Fri, 11 Oct 2024 07:39:25 +0200 Subject: [PATCH 1/2] Update to new ert.dark_storage api --- tests/data/snake_oil_data.py | 4 ++-- webviz_ert/data_loader/__init__.py | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/data/snake_oil_data.py b/tests/data/snake_oil_data.py index c55cd4b0..8ad1dc60 100644 --- a/tests/data/snake_oil_data.py +++ b/tests/data/snake_oil_data.py @@ -207,14 +207,14 @@ def to_parquet_helper(dataframe: pd.DataFrame) -> bytes: index=["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], ).transpose() ), - "http://127.0.0.1:5000/ensembles/3/records/WOPR:OP1": to_parquet_helper( + "http://127.0.0.1:5000/ensembles/3/records/WOPR%253AOP1": to_parquet_helper( pd.DataFrame( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], columns=[0], index=["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], ).transpose() ), - "http://127.0.0.1:5000/ensembles/3/records/WOPR:OP1/observations?realization_index=0": [ + "http://127.0.0.1:5000/ensembles/3/records/WOPR%253AOP1/observations?realization_index=0": [ { "x_axis": [1, 4], "errors": [1, 1], diff --git a/webviz_ert/data_loader/__init__.py b/webviz_ert/data_loader/__init__.py index 2c5d14ab..8ec81099 100644 --- a/webviz_ert/data_loader/__init__.py +++ b/webviz_ert/data_loader/__init__.py @@ -1,7 +1,8 @@ import io import logging from collections import defaultdict -from typing import Any, Dict, List, Mapping, MutableMapping, Optional, Tuple +from urllib.parse import quote +from typing import Any, List, Mapping, MutableMapping, Optional, Tuple import pandas as pd import requests @@ -11,6 +12,10 @@ connection_info_map: dict = {} +def escape(s: str) -> str: + return quote(quote(s, safe="")) + + def get_connection_info(project_id: Optional[str] = None) -> Mapping[str, str]: from ert.shared.storage.connection import get_info @@ -140,7 +145,7 @@ def get_ensemble_parameters(self, ensemble_id: str) -> list: def get_record_labels(self, ensemble_id: str, name: str) -> list: try: return self._get( - url=f"ensembles/{ensemble_id}/records/{name}/labels" + url=f"ensembles/{ensemble_id}/records/{escape(name)}/labels" ).json() except DataLoaderException as e: logger.error(e) @@ -168,7 +173,7 @@ def get_ensemble_parameter_data( params = {} resp = self._get( - url=f"ensembles/{ensemble_id}/records/{name}", + url=f"ensembles/{ensemble_id}/records/{escape(name)}", headers={"accept": "application/x-parquet"}, params=params, ) @@ -186,7 +191,7 @@ def get_ensemble_record_data( ) -> pd.DataFrame: try: resp = self._get( - url=f"ensembles/{ensemble_id}/records/{record_name}", + url=f"ensembles/{ensemble_id}/records/{escape(record_name)}", headers={"accept": "application/x-parquet"}, ) stream = io.BytesIO(resp.content) @@ -210,7 +215,7 @@ def get_ensemble_record_observations( ) -> List[dict]: try: return self._get( - url=f"ensembles/{ensemble_id}/records/{record_name}/observations", + url=f"ensembles/{ensemble_id}/records/{escape(record_name)}/observations", # Hard coded to zero, as all realizations are connected to the same observations params={"realization_index": 0}, ).json() From ac49dd102dc4b766e5a462dfa1c59e8fc0e4a7b8 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Fri, 11 Oct 2024 09:54:29 +0200 Subject: [PATCH 2/2] Only run black on 3.11 black no longer supports 3.8 --- .github/workflows/python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3cc7d061..eb6f4475 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -35,4 +35,5 @@ jobs: pytest - name: Run black + if: ${{ matrix.python-version == '3.11'}} uses: psf/black@stable