Skip to content

Commit

Permalink
Pull request #112: Hotfix/HYP-354 hypergraph.collapse methods have ba…
Browse files Browse the repository at this point in the history
…d documentation and deprecation warnings aren t

Merge in HYP/hypernetx from hotfix/HYP-354-hypergraph.collapse_-methods-have-bad-documentation-and-deprecation-warnings-aren-t to master

* commit '677895b0677ade095fac8824a3ccbe6f8766ab76':
  bump: version 2.0.4 → 2.0.5
  HYP-354 Fix docstrings and display deprecation warnings
  • Loading branch information
bonicim authored and brendapraggastis committed Oct 6, 2023
2 parents f861138 + 677895b commit 38638a6
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .cz.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hypernetx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
from hypernetx.utils import *
from hypernetx.utils.toys import *

__version__ = "2.0.4"
__version__ = "2.0.5"
8 changes: 5 additions & 3 deletions hypernetx/classes/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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[
Expand Down
2 changes: 1 addition & 1 deletion hypernetx/classes/entityset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down
59 changes: 27 additions & 32 deletions hypernetx/classes/hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -326,7 +328,6 @@ def __init__(
### cell properties

if setsystem is None: #### Empty Case

self._edges = EntitySet({})
self._nodes = EntitySet({})
self._state_dict = {}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 = """
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from setuptools import setup

__version__ = "2.0.4"
__version__ = "2.0.5"

setup(version=__version__)

0 comments on commit 38638a6

Please sign in to comment.