diff --git a/.cz.toml b/.cz.toml index 74777d5f..58087e27 100644 --- a/.cz.toml +++ b/.cz.toml @@ -1,6 +1,6 @@ [tool.commitizen] name = "cz_conventional_commits" -version = "2.0.4" +version = "2.0.5" version_files = [ "setup.py", "docs/source/conf.py", diff --git a/docs/source/conf.py b/docs/source/conf.py index c20cb7af..360b891c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,7 +19,7 @@ import os -__version__ = "2.0.4" +__version__ = "2.0.5" # If extensions (or modules to document with autodoc) are in another directory, diff --git a/hypernetx/__init__.py b/hypernetx/__init__.py index 5e131e5f..5134716b 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.4" +__version__ = "2.0.5" diff --git a/hypernetx/classes/entityset.py b/hypernetx/classes/entityset.py index adf47c21..bfded939 100644 --- a/hypernetx/classes/entityset.py +++ b/hypernetx/classes/entityset.py @@ -589,7 +589,6 @@ def elements_by_level(self, level1: int, level2: int) -> dict[Any, AttrList]: return self.elements_by_column(col1, col2) def elements_by_column(self, col1: Hashable, col2: Hashable) -> dict[Any, AttrList]: - """System of sets representation of two columns (levels) of the underlying data table Each item in col1 defines a set containing all the col2 items @@ -2009,7 +2008,7 @@ def collapse_identical_elements( # group by level 0 (set), aggregate level 1 (set elements) as frozenset collapse = ( self._dataframe[self._data_cols] - .groupby(self._data_cols[0], as_index=False) + .groupby(self._data_cols[0], as_index=False, observed=False) .agg(frozenset) ) @@ -2133,7 +2132,6 @@ def restrict_to_two_columns( # if a 2D ndarray is passed, restrict to two columns if needed elif isinstance(data, np.ndarray): - if data.ndim == 2 and data.shape[1] > 2: data = data[:, (level1, level2)] diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index 203982d4..63821d08 100644 --- a/hypernetx/classes/hypergraph.py +++ b/hypernetx/classes/hypergraph.py @@ -2,8 +2,10 @@ # All rights reserved. from __future__ import annotations -import pickle import warnings + +warnings.filterwarnings("default", category=DeprecationWarning) + from copy import deepcopy from collections import defaultdict from collections.abc import Sequence, Iterable @@ -15,7 +17,7 @@ from networkx.algorithms import bipartite from scipy.sparse import coo_matrix, csr_matrix -from hypernetx.classes import EntitySet, EntitySet +from hypernetx.classes import EntitySet from hypernetx.exception import HyperNetXError from hypernetx.utils.decorators import warn_nwhy from hypernetx.classes.helpers import merge_nested_dicts, dict_depth @@ -1341,7 +1343,7 @@ def collapse_nodes( return_equivalence_classes=False, use_reps=None, return_counts=None, - ): + ) -> Hypergraph: """ Constructs a new hypergraph gotten by identifying nodes contained by the same edges @@ -1354,15 +1356,15 @@ def collapse_nodes( Returns a dictionary of node equivalence classes keyed by frozen sets of edges - use_reps : boolean, optional, default = False - Deprecated, this no - longer works and will be removed. Choose a single element from the + use_reps : boolean, optional, default = None + [DEPRECATED; WILL BE REMOVED IN NEXT RELEASE] Choose a single element from the collapsed nodes as uid for the new node, otherwise uses a frozen - set of the uids of nodes in the equivalence class - - return_counts: boolean, - Deprecated, this no longer works and will be - removed if use_reps is True the new nodes have uids given by a + set of the uids of nodes in the equivalence class. If use_reps is True the new nodes have uids given by a tuple of the rep and the count + return_counts: boolean, optional, default = None + [DEPRECATED; WILL BE REMOVED IN NEXT RELEASE] + Returns ------- new hypergraph : Hypergraph @@ -1378,16 +1380,10 @@ def collapse_nodes( Example ------- - >>> h = Hypergraph(EntitySet('example',elements=[EntitySet('E1', / - ['a','b']),Entity('E2',['a','b'])])) - >>> h.incidence_dict - {'E1': {'a', 'b'}, 'E2': {'a', 'b'}} + >>> data = {'E1': ('a', 'b'), 'E2': ('a', 'b')})) + >>> h = Hypergraph(data) >>> h.collapse_nodes().incidence_dict - {'E1': {frozenset({'a', 'b'})}, 'E2': {frozenset({'a', 'b'})}} - ### Fix this - >>> h.collapse_nodes(use_reps=True).incidence_dict - {'E1': {('a', 2)}, 'E2': {('a', 2)}} - + {'E1': ['a: 2'], 'E2': ['a: 2']} """ if use_reps is not None or return_counts is not None: msg = """ @@ -1421,25 +1417,25 @@ def collapse_nodes_and_edges( name: str, optional, default = None - use_reps: boolean, optional, default = False - Choose a single element from the collapsed elements as a - representative - - return_counts: boolean, optional, default = True - if use_reps is True the new elements are keyed by a tuple of the - rep and the count - return_equivalence_classes: boolean, optional, default = False Returns a dictionary of edge equivalence classes keyed by frozen sets of nodes + use_reps: boolean, optional, default = None + [DEPRECATED; WILL BE REMOVED IN NEXT RELEASE] Choose a single element from the collapsed elements as a + representative. If use_reps is True, the new elements are keyed by a tuple of the + rep and the count. + + return_counts: boolean, optional, default = None + [DEPRECATED; WILL BE REMOVED IN NEXT RELEASE] + Returns ------- new hypergraph : Hypergraph Notes ----- - Collapses the Nodes and Edges EntitySets. Two nodes(edges) are + Collapses the Nodes and Edges of EntitySets. Two nodes(edges) are duplicates if their respective memberships(elements) are the same. Using this as an equivalence relation, the uids of the nodes(edges) are partitioned into equivalence classes. A single member of the @@ -1449,12 +1445,12 @@ def collapse_nodes_and_edges( Example ------- - >>> h = Hypergraph(EntitySet('example',elements=[EntitySet('E1', / - ['a','b']),Entity('E2',['a','b'])])) + >>> data = {'E1': ('a', 'b'), 'E2': ('a', 'b')} + >>> h = Hypergraph(data) >>> h.incidence_dict - {'E1': {'a', 'b'}, 'E2': {'a', 'b'}} - >>> h.collapse_nodes_and_edges().incidence_dict ### Fix this - {('E1', 2): {('a', 2)}} + {'E1': ['a', 'b'], 'E2': ['a', 'b']} + >>> h.collapse_nodes_and_edges().incidence_dict + {'E1: 2': ['a: 2']} """ if use_reps is not None or return_counts is not None: diff --git a/setup.py b/setup.py index d9697e1a..4864faee 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ from setuptools import setup -__version__ = "2.0.4" +__version__ = "2.0.5" setup(version=__version__)