From b0e8c9598c4552829d4e80f72d470ac1abb78fd5 Mon Sep 17 00:00:00 2001 From: mvogt Date: Thu, 7 Sep 2023 17:57:26 +0200 Subject: [PATCH 1/5] trying to fix some problems with pytest --- .github/workflows/github_test_action.yml | 4 ++-- .github/workflows/release.yml | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/github_test_action.yml b/.github/workflows/github_test_action.yml index 3087790..7e06179 100644 --- a/.github/workflows/github_test_action.yml +++ b/.github/workflows/github_test_action.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9', '3.10'] + python-version: ['3.9', '3.10', '3.11'] services: mongodb: @@ -27,7 +27,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install pytest + python -m pip install -U pytest pip install -r requirements.txt pip install -r requirements_dev.txt pip install .["all"] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d389c6..b1ae3c1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -76,7 +76,7 @@ jobs: needs: upload strategy: matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ['3.9', '3.10', '3.11'] os: [ ubuntu-latest, windows-latest ] steps: - name: Set up Python ${{ matrix.python-version }} @@ -86,8 +86,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install pytest python-igraph pytest-split - if ${{ matrix.python-version != '3.11' }}; then python -m pip install numba; fi + python -m pip install -U pytest python-igraph pytest-split - name: Install pandahub from TestPyPI if: ${{ inputs.upload_server == 'testpypi'}} run: | From fa0e5a7f9e460447460c6208697ffab70485985c Mon Sep 17 00:00:00 2001 From: Leon Hillmann Date: Mon, 11 Sep 2023 17:43:06 +0200 Subject: [PATCH 2/5] Fix: Return value of `create_elements_in_db` The `PandaHub.create_elements_in_db` function used to return a list of `None`s, since it used the `update` function of a Python dict, which returns `None` and not the updated dictionary. Fix this by using the overloaded `|` operator for dictionaries instead, so that `create_elements_in_db` returns a list of dictionaries with the properties of the newly created elements. --- pandahub/lib/PandaHub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandahub/lib/PandaHub.py b/pandahub/lib/PandaHub.py index 1fdd9a5..4ee32d6 100644 --- a/pandahub/lib/PandaHub.py +++ b/pandahub/lib/PandaHub.py @@ -1085,7 +1085,7 @@ def create_elements_in_db(self, net: Union[int,str], element_type: str, elements data.append({**elm_data, **var_data, "net_id": net_id}) collection = self._collection_name_of_element(element_type) insert_result = db[collection].insert_many(data) - return [[z[0].update(_id=z[1]) for z in zip(data, insert_result.inserted_ids)]] + return [z[0] | {"_id": z[1]} for z in zip(data, insert_result.inserted_ids)] def _add_missing_defaults(self, db, net_id, element_type, element_data): func_str = f"create_{element_type}" From 36242365b28b9bdebdf225c99ca18597e5e6b310 Mon Sep 17 00:00:00 2001 From: mvogt Date: Wed, 13 Sep 2023 11:27:33 +0200 Subject: [PATCH 3/5] added missing optional project_id for some functions. --- pandahub/lib/PandaHub.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pandahub/lib/PandaHub.py b/pandahub/lib/PandaHub.py index 1fdd9a5..2d38707 100644 --- a/pandahub/lib/PandaHub.py +++ b/pandahub/lib/PandaHub.py @@ -1109,7 +1109,7 @@ def _add_missing_defaults(self, db, net_id, element_type, element_data): std_type = element_data["std_type"] net_doc = db["_networks"].find_one({"_id": net_id}) if net_doc is not None: -# std_types = json.loads(net_doc["data"]["std_types"], cls=io_pp.PPJSONDecoder)[element_type] + # std_types = json.loads(net_doc["data"]["std_types"], cls=io_pp.PPJSONDecoder)[element_type] std_types = net_doc["data"]["std_types"] if std_type in std_types: element_data.update(std_types[std_type]) @@ -1238,7 +1238,7 @@ def bulk_write_to_db(self, data, collection_name="tasks", global_database=True, for d in data] db[collection_name].bulk_write(operations) - def bulk_update_in_db(self, data, document_ids, collection_name="tasks", global_database=False): + def bulk_update_in_db(self, data, document_ids, collection_name="tasks", global_database=False, project_id=None): """ Updates any number of documents in the database at once, according to their document_ids. @@ -1260,6 +1260,8 @@ def bulk_update_in_db(self, data, document_ids, collection_name="tasks", global_ None. """ + if project_id: + self.set_active_project_by_id(project_id) if global_database: db = self._get_global_database() else: @@ -1367,6 +1369,7 @@ def bulk_write_timeseries_to_db(self, timeseries, data_type, compress_ts_data=False, global_database=False, collection_name="timeseries", + project_id=None, **kwargs): """ This function can be used to write a pandas DataFrame, containing multiple @@ -1412,6 +1415,8 @@ def bulk_write_timeseries_to_db(self, timeseries, data_type, """ documents = [] + if project_id: + self.set_active_project_by_id(project_id) for col in timeseries.columns: if meta_frame is not None: args = {**kwargs, **meta_frame.loc[col]} @@ -1430,7 +1435,7 @@ def bulk_write_timeseries_to_db(self, timeseries, data_type, return [d["_id"] for d in documents] def update_timeseries_in_db(self, new_ts_content, document_id, collection_name="timeseries", - global_database=False): + global_database=False, project_id=None): """ This function can be used to append a timeseries to an existing timseries @@ -1457,6 +1462,8 @@ def update_timeseries_in_db(self, new_ts_content, document_id, collection_name=" None. """ + if project_id: + self.set_active_project_by_id(project_id) if global_database: db = self._get_global_database() else: @@ -1469,7 +1476,7 @@ def update_timeseries_in_db(self, new_ts_content, document_id, collection_name=" ) # logger.info("document updated in database") - def bulk_update_timeseries_in_db(self, new_ts_content, document_ids, collection_name="timeseries", + def bulk_update_timeseries_in_db(self, new_ts_content, document_ids, project_id=None, collection_name="timeseries", global_database=False): """ @@ -1499,13 +1506,16 @@ def bulk_update_timeseries_in_db(self, new_ts_content, document_ids, collection_ ------- None """ + if project_id: + self.set_active_project_by_id(project_id) + documents = [] for i in range(len(new_ts_content.columns)): col = new_ts_content.columns[i] document = {} document["timeseries_data"] = {"$each": convert_timeseries_to_subdocuments(new_ts_content[col])} documents.append(document) - self.bulk_update_in_db(documents, document_ids, project=project, + self.bulk_update_in_db(documents, document_ids, project_id=project_id, collection_name="timeseries", global_database=global_database) # logger.debug(f"{len(documents)} documents added to database") From 12171153cfec90f2ff5de2f1893a921ba58af85e Mon Sep 17 00:00:00 2001 From: mvogt Date: Tue, 19 Sep 2023 07:48:40 +0200 Subject: [PATCH 4/5] using by_id since it allows for faster access. --- pandahub/lib/PandaHub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandahub/lib/PandaHub.py b/pandahub/lib/PandaHub.py index a40090b..2d85918 100644 --- a/pandahub/lib/PandaHub.py +++ b/pandahub/lib/PandaHub.py @@ -516,7 +516,7 @@ def remove_user_from_project(self, email): def get_all_nets_metadata_from_db(self, project_id=None): if project_id: - self.set_active_project(project_id) + self.set_active_project_by_id(project_id) self.check_permission('read') db = self._get_project_database() return list(db['_networks'].find()) From f4bfed5f4511dc7578c8c5f4d747787b3e3e2372 Mon Sep 17 00:00:00 2001 From: mvogt Date: Wed, 20 Sep 2023 15:19:36 +0200 Subject: [PATCH 5/5] bump version --- pandahub/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandahub/__init__.py b/pandahub/__init__.py index 1cc4a03..194a810 100644 --- a/pandahub/__init__.py +++ b/pandahub/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.2.7" +__version__ = "0.2.8" from pandahub.lib.PandaHub import PandaHub, PandaHubError from pandahub.client.PandaHubClient import PandaHubClient diff --git a/setup.py b/setup.py index 8c40e93..264167c 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ name='pandahub', packages=find_packages(), url='https://github.com/e2nIEE/pandahub', - version='0.2.7', + version='0.2.8', include_package_data=True, long_description_content_type='text/markdown', zip_safe=False,