From e0950e36a2c11da4b0aa0f73fd4225ea7595610b Mon Sep 17 00:00:00 2001 From: Brenda Praggastis <39808911+brendapraggastis@users.noreply.github.com> Date: Fri, 25 Aug 2023 16:01:35 -0700 Subject: [PATCH 1/7] updated Hypergraph.dual() to deepcopy the dataframes to separate base data from H and H.dual() --- hypernetx/classes/hypergraph.py | 17 +++++++++-------- hypernetx/classes/tests/conftest.py | 2 +- hypernetx/classes/tests/test_hypergraph.py | 6 ++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index 952ab195..d466ec91 100644 --- a/hypernetx/classes/hypergraph.py +++ b/hypernetx/classes/hypergraph.py @@ -4,6 +4,7 @@ import pickle import warnings +from copy import deepcopy from collections import defaultdict from collections.abc import Sequence, Iterable from typing import Optional, Any, TypeVar, Union, Mapping, Hashable @@ -1242,22 +1243,22 @@ def dual(self, name=None, switch_names=True): : hypergraph """ - dfp = self.edges.properties.copy() - if "level" in dfp.columns: - dfp = dfp.reset_index() - dfp.level = dfp.level.apply(lambda x: 1 * (x == 0)) - dfp = dfp.set_index(["level", "id"]) + dfp = deepcopy(self.edges.properties) + dfp = dfp.reset_index() + dfp.level = dfp.level.apply(lambda x: 1 * (x == 0)) + dfp = dfp.set_index(["level", "id"]) edge, node, wt = self._edge_col, self._node_col, self._cell_weight_col - df = self.dataframe.copy() + df = deepcopy(self.dataframe) cprops = [col for col in df.columns if not col in [edge, node, wt]] df[[edge, node]] = df[[node, edge]] - if edge != "edges" or node != "nodes": + if switch_names == True and not (self._edge_col == 'edges' and self._node_col == 'nodes'): + # if switch_names == False or (self._edge_col == 'edges' and self._node_col == 'nodes'): df = df.rename(columns={edge: self._node_col, node: self._edge_col}) node = self._edge_col edge = self._node_col - + return Hypergraph( df, edge_col=edge, diff --git a/hypernetx/classes/tests/conftest.py b/hypernetx/classes/tests/conftest.py index a4c7eae8..ef636ea5 100644 --- a/hypernetx/classes/tests/conftest.py +++ b/hypernetx/classes/tests/conftest.py @@ -173,7 +173,7 @@ def triloop2(): @pytest.fixture def sbs_hypergraph(sbs): - return Hypergraph(sbs.edgedict, name="sbsh") + return Hypergraph(sbs.edgedict, name="sbsh",edge_col='edges',node_col='nodes') @pytest.fixture diff --git a/hypernetx/classes/tests/test_hypergraph.py b/hypernetx/classes/tests/test_hypergraph.py index 3f8f5228..6b5cd669 100644 --- a/hypernetx/classes/tests/test_hypergraph.py +++ b/hypernetx/classes/tests/test_hypergraph.py @@ -308,6 +308,12 @@ def test_dual(sbs_hypergraph): HD = H.dual() assert set(H.nodes) == set(HD.edges) assert set(H.edges) == set(HD.nodes) + assert list(H.dataframe.columns)== list(HD.dataframe.columns) + +def test_dual_again(sbs_edgedict): + H = Hypergraph(sbs_edgedict,edge_col='Types',node_col='Values') + assert list(H.dataframe.columns[0:2]) == ['Types','Values'] + assert list(H.dual().dataframe.columns[0:2]) == ['Values','Types'] @pytest.mark.filterwarnings("ignore:No 3-path between ME and FN") From c2aeaf5055531c63e60d7b0e5096bebddeb918c2 Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Mon, 28 Aug 2023 10:46:45 -0700 Subject: [PATCH 2/7] HYP-347 Fix formatting --- hypernetx/classes/hypergraph.py | 8 +++++--- hypernetx/classes/tests/conftest.py | 2 +- hypernetx/classes/tests/test_hypergraph.py | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index d466ec91..6c3663b7 100644 --- a/hypernetx/classes/hypergraph.py +++ b/hypernetx/classes/hypergraph.py @@ -1253,12 +1253,14 @@ def dual(self, name=None, switch_names=True): cprops = [col for col in df.columns if not col in [edge, node, wt]] df[[edge, node]] = df[[node, edge]] - if switch_names == True and not (self._edge_col == 'edges' and self._node_col == 'nodes'): - # if switch_names == False or (self._edge_col == 'edges' and self._node_col == 'nodes'): + if switch_names == True and not ( + self._edge_col == "edges" and self._node_col == "nodes" + ): + # if switch_names == False or (self._edge_col == 'edges' and self._node_col == 'nodes'): df = df.rename(columns={edge: self._node_col, node: self._edge_col}) node = self._edge_col edge = self._node_col - + return Hypergraph( df, edge_col=edge, diff --git a/hypernetx/classes/tests/conftest.py b/hypernetx/classes/tests/conftest.py index ef636ea5..ddfdb22e 100644 --- a/hypernetx/classes/tests/conftest.py +++ b/hypernetx/classes/tests/conftest.py @@ -173,7 +173,7 @@ def triloop2(): @pytest.fixture def sbs_hypergraph(sbs): - return Hypergraph(sbs.edgedict, name="sbsh",edge_col='edges',node_col='nodes') + return Hypergraph(sbs.edgedict, name="sbsh", edge_col="edges", node_col="nodes") @pytest.fixture diff --git a/hypernetx/classes/tests/test_hypergraph.py b/hypernetx/classes/tests/test_hypergraph.py index 6b5cd669..18ad5f0c 100644 --- a/hypernetx/classes/tests/test_hypergraph.py +++ b/hypernetx/classes/tests/test_hypergraph.py @@ -308,12 +308,13 @@ def test_dual(sbs_hypergraph): HD = H.dual() assert set(H.nodes) == set(HD.edges) assert set(H.edges) == set(HD.nodes) - assert list(H.dataframe.columns)== list(HD.dataframe.columns) + assert list(H.dataframe.columns) == list(HD.dataframe.columns) + def test_dual_again(sbs_edgedict): - H = Hypergraph(sbs_edgedict,edge_col='Types',node_col='Values') - assert list(H.dataframe.columns[0:2]) == ['Types','Values'] - assert list(H.dual().dataframe.columns[0:2]) == ['Values','Types'] + H = Hypergraph(sbs_edgedict, edge_col="Types", node_col="Values") + assert list(H.dataframe.columns[0:2]) == ["Types", "Values"] + assert list(H.dual().dataframe.columns[0:2]) == ["Values", "Types"] @pytest.mark.filterwarnings("ignore:No 3-path between ME and FN") From 766f41a30bea87e32310ff92843e92884b4fc6b3 Mon Sep 17 00:00:00 2001 From: Brenda Praggastis <39808911+brendapraggastis@users.noreply.github.com> Date: Tue, 29 Aug 2023 11:47:46 -0700 Subject: [PATCH 3/7] changed deepcopy to pandas copy deep=True --- hypernetx/classes/hypergraph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index d466ec91..8b69ecd0 100644 --- a/hypernetx/classes/hypergraph.py +++ b/hypernetx/classes/hypergraph.py @@ -1243,13 +1243,13 @@ def dual(self, name=None, switch_names=True): : hypergraph """ - dfp = deepcopy(self.edges.properties) + dfp = self.edges.properties.copy(deep=True) dfp = dfp.reset_index() dfp.level = dfp.level.apply(lambda x: 1 * (x == 0)) dfp = dfp.set_index(["level", "id"]) edge, node, wt = self._edge_col, self._node_col, self._cell_weight_col - df = deepcopy(self.dataframe) + df = self.dataframe.copy(deep=True) cprops = [col for col in df.columns if not col in [edge, node, wt]] df[[edge, node]] = df[[node, edge]] From 0429c5f12d76e0bf6b80596522a933c365aab31a Mon Sep 17 00:00:00 2001 From: Brenda Praggastis <39808911+brendapraggastis@users.noreply.github.com> Date: Tue, 29 Aug 2023 11:52:40 -0700 Subject: [PATCH 4/7] added test for dual not switching column names --- hypernetx/classes/tests/test_hypergraph.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hypernetx/classes/tests/test_hypergraph.py b/hypernetx/classes/tests/test_hypergraph.py index 18ad5f0c..5853df54 100644 --- a/hypernetx/classes/tests/test_hypergraph.py +++ b/hypernetx/classes/tests/test_hypergraph.py @@ -315,6 +315,7 @@ def test_dual_again(sbs_edgedict): H = Hypergraph(sbs_edgedict, edge_col="Types", node_col="Values") assert list(H.dataframe.columns[0:2]) == ["Types", "Values"] assert list(H.dual().dataframe.columns[0:2]) == ["Values", "Types"] + assert list(H.dual(switch_names=False).dataframe.columns[0:2]) == ["Types","Values"] @pytest.mark.filterwarnings("ignore:No 3-path between ME and FN") From 9ba04f2209c2edc33df5db4cf07aee8d9fce41f7 Mon Sep 17 00:00:00 2001 From: Brenda Praggastis <39808911+brendapraggastis@users.noreply.github.com> Date: Tue, 29 Aug 2023 11:59:03 -0700 Subject: [PATCH 5/7] put deepcopy back --- hypernetx/classes/hypergraph.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index cedf7a8f..d466ec91 100644 --- a/hypernetx/classes/hypergraph.py +++ b/hypernetx/classes/hypergraph.py @@ -1243,24 +1243,22 @@ def dual(self, name=None, switch_names=True): : hypergraph """ - dfp = self.edges.properties.copy(deep=True) + dfp = deepcopy(self.edges.properties) dfp = dfp.reset_index() dfp.level = dfp.level.apply(lambda x: 1 * (x == 0)) dfp = dfp.set_index(["level", "id"]) edge, node, wt = self._edge_col, self._node_col, self._cell_weight_col - df = self.dataframe.copy(deep=True) + df = deepcopy(self.dataframe) cprops = [col for col in df.columns if not col in [edge, node, wt]] df[[edge, node]] = df[[node, edge]] - if switch_names == True and not ( - self._edge_col == "edges" and self._node_col == "nodes" - ): - # if switch_names == False or (self._edge_col == 'edges' and self._node_col == 'nodes'): + if switch_names == True and not (self._edge_col == 'edges' and self._node_col == 'nodes'): + # if switch_names == False or (self._edge_col == 'edges' and self._node_col == 'nodes'): df = df.rename(columns={edge: self._node_col, node: self._edge_col}) node = self._edge_col edge = self._node_col - + return Hypergraph( df, edge_col=edge, From dc51613cb2574fc1f9e15d988d0874611c101cae Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Wed, 30 Aug 2023 09:28:27 -0700 Subject: [PATCH 6/7] Fix formatting --- hypernetx/classes/hypergraph.py | 8 +++++--- hypernetx/classes/tests/test_hypergraph.py | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index d466ec91..6c3663b7 100644 --- a/hypernetx/classes/hypergraph.py +++ b/hypernetx/classes/hypergraph.py @@ -1253,12 +1253,14 @@ def dual(self, name=None, switch_names=True): cprops = [col for col in df.columns if not col in [edge, node, wt]] df[[edge, node]] = df[[node, edge]] - if switch_names == True and not (self._edge_col == 'edges' and self._node_col == 'nodes'): - # if switch_names == False or (self._edge_col == 'edges' and self._node_col == 'nodes'): + if switch_names == True and not ( + self._edge_col == "edges" and self._node_col == "nodes" + ): + # if switch_names == False or (self._edge_col == 'edges' and self._node_col == 'nodes'): df = df.rename(columns={edge: self._node_col, node: self._edge_col}) node = self._edge_col edge = self._node_col - + return Hypergraph( df, edge_col=edge, diff --git a/hypernetx/classes/tests/test_hypergraph.py b/hypernetx/classes/tests/test_hypergraph.py index 5853df54..5f21d5a7 100644 --- a/hypernetx/classes/tests/test_hypergraph.py +++ b/hypernetx/classes/tests/test_hypergraph.py @@ -315,7 +315,10 @@ def test_dual_again(sbs_edgedict): H = Hypergraph(sbs_edgedict, edge_col="Types", node_col="Values") assert list(H.dataframe.columns[0:2]) == ["Types", "Values"] assert list(H.dual().dataframe.columns[0:2]) == ["Values", "Types"] - assert list(H.dual(switch_names=False).dataframe.columns[0:2]) == ["Types","Values"] + assert list(H.dual(switch_names=False).dataframe.columns[0:2]) == [ + "Types", + "Values", + ] @pytest.mark.filterwarnings("ignore:No 3-path between ME and FN") From 89917e5cebb48cbe655a3882320eb848968cf625 Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Wed, 30 Aug 2023 10:32:10 -0700 Subject: [PATCH 7/7] =?UTF-8?q?bump:=20version=202.0.3=20=E2=86=92=202.0.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cz.toml | 2 +- docs/source/conf.py | 2 +- hypernetx/__init__.py | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.cz.toml b/.cz.toml index b8265df3..74777d5f 100644 --- a/.cz.toml +++ b/.cz.toml @@ -1,6 +1,6 @@ [tool.commitizen] name = "cz_conventional_commits" -version = "2.0.3" +version = "2.0.4" version_files = [ "setup.py", "docs/source/conf.py", diff --git a/docs/source/conf.py b/docs/source/conf.py index 433c2b18..c20cb7af 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,7 +19,7 @@ import os -__version__ = "2.0.3" +__version__ = "2.0.4" # If extensions (or modules to document with autodoc) are in another directory, diff --git a/hypernetx/__init__.py b/hypernetx/__init__.py index 21723aaa..5e131e5f 100644 --- a/hypernetx/__init__.py +++ b/hypernetx/__init__.py @@ -11,4 +11,4 @@ from hypernetx.utils import * from hypernetx.utils.toys import * -__version__ = "2.0.3" +__version__ = "2.0.4" diff --git a/setup.py b/setup.py index edea8c23..d9697e1a 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ from setuptools import setup -__version__ = "2.0.3" +__version__ = "2.0.4" setup(version=__version__)