From 16809205403a7b2ef002938ad6277617bc6821ea Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Fri, 6 Oct 2023 14:06:29 -0700 Subject: [PATCH 1/2] HYP-354 Fix docstrings and display deprecation warnings --- hypernetx/classes/entity.py | 8 +++-- hypernetx/classes/entityset.py | 2 +- hypernetx/classes/hypergraph.py | 59 +++++++++++++++------------------ 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/hypernetx/classes/entity.py b/hypernetx/classes/entity.py index 81a80be6..c1dc78c9 100644 --- a/hypernetx/classes/entity.py +++ b/hypernetx/classes/entity.py @@ -542,7 +542,6 @@ def elements_by_level(self, level1, level2): return self.elements_by_column(col1, col2) def elements_by_column(self, col1, col2): - """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 @@ -572,7 +571,9 @@ def elements_by_column(self, col1, col2): self._state_dict["elements"] = defaultdict(dict) if col2 not in self._state_dict["elements"][col1]: level = self.index(col1) - elements = self._dataframe.groupby(col1)[col2].unique().to_dict() + elements = ( + self._dataframe.groupby(col1, observed=False)[col2].unique().to_dict() + ) self._state_dict["elements"][col1][col2] = { item: AttrList(entity=self, key=(level, item), initlist=elem) for item, elem in elements.items() @@ -1378,13 +1379,14 @@ def _properties_from_dataframe(self, props: pd.DataFrame) -> None: pass # data already parsed, no literal eval needed else: warnings.warn("parsed property dict column from string literal") - if props.index.nlevels == 1: props = props.reindex(self.properties.index, level=1) # combine with existing properties # non-null values in new props override existing value + warnings.simplefilter(action="ignore", category=RuntimeWarning) properties = props.combine_first(self.properties) + warnings.simplefilter(action="default", category=RuntimeWarning) # update misc. column to combine existing and new misc. property dicts # new props override existing value for overlapping misc. property dict keys properties[self._misc_props_col] = self.properties[ diff --git a/hypernetx/classes/entityset.py b/hypernetx/classes/entityset.py index c0c1b97d..05e0c721 100644 --- a/hypernetx/classes/entityset.py +++ b/hypernetx/classes/entityset.py @@ -531,7 +531,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) ) diff --git a/hypernetx/classes/hypergraph.py b/hypernetx/classes/hypergraph.py index 6c3663b7..3e8c7671 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 @@ -326,7 +328,6 @@ def __init__( ### cell properties if setsystem is None: #### Empty Case - self._edges = EntitySet({}) self._nodes = EntitySet({}) self._state_dict = {} @@ -1336,7 +1337,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 @@ -1349,15 +1350,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 @@ -1373,16 +1374,10 @@ def collapse_nodes( Example ------- - >>> h = Hypergraph(EntitySet('example',elements=[Entity('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 = """ @@ -1416,25 +1411,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 @@ -1444,12 +1439,12 @@ def collapse_nodes_and_edges( Example ------- - >>> h = Hypergraph(EntitySet('example',elements=[Entity('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: From 677895b0677ade095fac8824a3ccbe6f8766ab76 Mon Sep 17 00:00:00 2001 From: Mark Bonicillo Date: Fri, 6 Oct 2023 14:10:43 -0700 Subject: [PATCH 2/2] =?UTF-8?q?bump:=20version=202.0.4=20=E2=86=92=202.0.5?= 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 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/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__)