Skip to content

Commit

Permalink
Merge pull request #91 from pnnl/updated-master
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
brendapraggastis authored Aug 15, 2022
2 parents 33ac4a1 + 6feeec0 commit fa6bd85
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ tutorials/h2d-hnx-why_v5.tar.gz
vis_develop
dist/
*.egg-info*
.tox/
venv*
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

SHELL = /bin/bash

# Variables
VENV = venv_test
PYTHON = $(VENV)/bin/python

## Environment

venv:
@rm -rf VENV;
@python -m venv $(VENV);

deps:
@$(PYTHON) -m pip install tox

.PHONY: venv deps

## Test

test: venv deps
rm -rf .tox
@$(PYTHON) -m tox

.PHONY: test

clean:
rm -rf .out .pytest_cache .tox *.egg-info dist build

.PHONY: clean
4 changes: 2 additions & 2 deletions hypernetx/classes/hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ def dataframe(self, sort_rows=False, sort_columns=False, cell_weights=True):

@classmethod
def from_bipartite(
cls, B, set_names=("nodes", "edges"), name=None, static=False, use_nwhy=False
cls, B, set_names=("edges", "nodes"), name=None, static=False, use_nwhy=False
):
"""
Static method creates a Hypergraph from a bipartite graph.
Expand Down Expand Up @@ -2356,7 +2356,7 @@ def from_bipartite(
if static:
elist = []
for e in list(B.edges):
if e[0] in nodes:
if e[0] in edges:
elist.append([e[0], e[1]])
else:
elist.append([e[1], e[0]])
Expand Down
25 changes: 23 additions & 2 deletions hypernetx/classes/tests/test_hypergraph_constructors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from collections import OrderedDict

import pytest
import numpy as np
import pandas as pd
import networkx as nx
from hypernetx import Hypergraph, Entity, EntitySet
from hypernetx import HyperNetXError
from hypernetx import Hypergraph, EntitySet



def test_from_bipartite():
Expand All @@ -17,6 +19,25 @@ def test_from_bipartite():
assert "Hypergraph is not s-connected." in str(excinfo.value)


@pytest.mark.parametrize("static", [(True), (False)])
def test_hypergraph_from_bipartite_and_from_constructor_should_be_equal(seven_by_six, static):
edgedict = OrderedDict(seven_by_six.edgedict)

bipartite_graph = Hypergraph(edgedict).bipartite()
hg_from_bipartite = Hypergraph.from_bipartite(bipartite_graph, static=static)

entityset = EntitySet("_", edgedict)
hg_from_constructor = Hypergraph(entityset, static=static)

assert hg_from_bipartite.isstatic == hg_from_constructor.isstatic

assert hg_from_bipartite.shape == hg_from_constructor.shape

incidence_dict_hg_from_bipartite = {key: sorted(value) for key, value in hg_from_bipartite.incidence_dict.items()}
incidence_dict_hg_from_constructor = {key: sorted(value) for key, value in hg_from_constructor.incidence_dict.items()}
assert incidence_dict_hg_from_bipartite == incidence_dict_hg_from_constructor


def test_from_numpy_array():
M = np.array([[0, 1, 1, 0, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0], [0, 0, 0, 0, 1]])
h = Hypergraph.from_numpy_array(M)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[metadata]
description-file=README.md
description_file=README.md

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"pandas>=0.23",
"python-igraph>=0.9.6",
"celluloid>=0.2.0",
"decorator>=5.1.1"
],
license="3-Clause BSD license",
long_description="""
Expand Down
13 changes: 13 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# tox (https://tox.readthedocs.io/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = py37

[testenv]
deps =
pytest
commands =
pytest hypernetx/ -v --disable-warnings

0 comments on commit fa6bd85

Please sign in to comment.