Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test GH Actions changes] #30

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c6a6a68
Very minor docstring change
CarlosBergillos Sep 10, 2023
7c42995
Update docs dependencies versions
CarlosBergillos Sep 10, 2023
914d771
Use new docs dependencies features
CarlosBergillos Sep 10, 2023
32b0982
Add mypy check to CI
CarlosBergillos Sep 13, 2023
6be3596
Trigger CI tests also with tests folder
CarlosBergillos Sep 13, 2023
e0ece22
Add types to summary.py
CarlosBergillos Sep 13, 2023
2f75030
Fix GH Action character typo
CarlosBergillos Sep 13, 2023
1c0d6c0
Separate type checking and tests jobs in CI
CarlosBergillos Sep 13, 2023
001f9ea
Fox types in summary.py
CarlosBergillos Sep 13, 2023
924887f
Drop support for Python 3.7
CarlosBergillos Sep 13, 2023
1822fdd
Add typing to base.py
CarlosBergillos Sep 15, 2023
bb8f864
Add typing to cli.py and use error return codes
CarlosBergillos Sep 15, 2023
ee8f27b
Add adjacency matrix with weights tests
CarlosBergillos Sep 15, 2023
ec2f7e1
Small wording fix
CarlosBergillos Sep 15, 2023
bf08941
Merge branch 'develop' into add-typing
CarlosBergillos Sep 15, 2023
8b13bec
Fix edges array and numpy dtypes
CarlosBergillos Sep 15, 2023
b642390
Add only_degrees tests
CarlosBergillos Sep 15, 2023
b9bd2cd
Merge branch 'develop' into add-typing
CarlosBergillos Sep 15, 2023
fc5616e
Tweak docstrings and naming
CarlosBergillos Sep 15, 2023
48505e6
Add degree counts and distr. tests & minor tweaks
CarlosBergillos Sep 15, 2023
eb022ae
Merge branch 'develop' into add-typing
CarlosBergillos Sep 15, 2023
69234a6
Add more types
CarlosBergillos Sep 17, 2023
15473aa
Add mypy config to pyproject.toml
CarlosBergillos Sep 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,38 @@ on:
branches: [main]
paths:
- ts2vg/**
- tests/**
pull_request:
branches: [main]

jobs:
type-check:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install ".[dev]"

- name: Run type checks
run: |
mypy

build-and-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- name: Checkout
Expand Down
18 changes: 0 additions & 18 deletions docs/source/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@
font-size: 0.8rem;
}

/* hidden block / drop down */
/* https://stackoverflow.com/questions/2454577/sphinx-restructuredtext-show-hide-code-snippets */
/* https://stackoverflow.com/questions/59679797/show-hide-part-of-text-question-answer-in-sphinx-file */

.toggle {
background: none repeat scroll 0 0 #e7f2fa;
}

.toggle.admonition {
padding: 0 .6rem 0!important;
}

.toggle .admonition-title {
display: block;
clear: both;
cursor: pointer;
}

/* logo-like */

.ts2vg, .navbar-brand p.title {
Expand Down
21 changes: 8 additions & 13 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"sphinx.ext.linkcode",
"sphinx.ext.autosummary",
"sphinx.ext.autosectionlabel",
"sphinx_favicon",
"sphinx_togglebutton",
]

autoclass_content = "class"
Expand Down Expand Up @@ -70,21 +72,9 @@
html_copy_source = False
html_show_sourcelink = False

html_favicon = "_static/favicon-32x32.png"
html_title = f"{project} v{version}"

html_theme_options = {
"favicons": [
{
"rel": "icon",
"sizes": "16x16",
"href": "favicon-16x16.png",
},
{
"rel": "icon",
"sizes": "32x32",
"href": "favicon-32x32.png",
},
],
"icon_links": [
{
"name": "GitHub",
Expand All @@ -101,6 +91,11 @@
"navigation_with_keys": False,
}

favicons = [
"favicon-16x16.png",
"favicon-32x32.png",
]

# svg math output
# mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"

Expand Down
8 changes: 4 additions & 4 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ This example illustrates different options for the ``directed`` parameter when b


.. admonition:: Code for :meth:`plot_nvg`
:class: toggle
:class: dropdown

.. literalinclude:: examples/plot_utils.py
:language: python
Expand All @@ -99,7 +99,7 @@ See :ref:`Weighted graphs` for a complete list of available values for ``weighte


.. admonition:: Code for :meth:`plot_weighted_nvg`
:class: toggle
:class: dropdown

.. literalinclude:: examples/plot_utils.py
:language: python
Expand All @@ -124,7 +124,7 @@ Note that horizontal visibility graphs can also be directed and/or weighted.


.. admonition:: Code for :meth:`plot_utils`
:class: toggle
:class: dropdown

.. literalinclude:: examples/plot_utils.py
:language: python
Expand Down Expand Up @@ -156,7 +156,7 @@ Note that when ``penetrable_limit`` is 0, the behavior is exactly the same as a


.. admonition:: Code for :meth:`plot_nvg`, :meth:`plot_hvg`
:class: toggle
:class: dropdown

.. literalinclude:: examples/plot_utils.py
:language: python
Expand Down
24 changes: 14 additions & 10 deletions docs_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
accessible-pygments==0.0.4
alabaster==0.7.13
Babel==2.11.0
beautifulsoup4==4.11.1
Babel==2.12.1
beautifulsoup4==4.12.2
certifi==2023.7.22
charset-normalizer==3.0.1
docutils==0.16
charset-normalizer==3.2.0
docutils==0.20.1
idna==3.4
imagesize==1.4.1
Jinja2==3.0.3
MarkupSafe==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
packaging==23.0
pydata-sphinx-theme==0.6.3
pydata-sphinx-theme==0.13.3
Pygments==2.15.0
pytz==2022.7.1
requests==2.31.0
snowballstemmer==2.2.0
soupsieve==2.3.2.post1
Sphinx==3.5.4
Sphinx==7.2.5
sphinx-favicon==1.0.1
sphinx-togglebutton==0.3.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
sphinxcontrib-serializinghtml==1.1.9
sphinxcontrib.applehelp==1.0.3
urllib3==1.26.14
typing_extensions==4.7.1
urllib3==2.0.4
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,19 @@ build-backend = "setuptools.build_meta"
# "pytest",
# ]


[tool.mypy]
packages = ["ts2vg"]
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = [
"igraph",
"networkx",
"snap",
"ts2vg.graph._natural",
"ts2vg.graph._natural_penetrable",
"ts2vg.graph._horizontal",
"ts2vg.graph._horizontal_penetrable",
]
ignore_missing_imports = true
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ install_requires =
include = ts2vg*

[options.extras_require]
dev =
mypy==1.5.1
tests =
pytest
pytest==7.4.2

[options.entry_points]
console_scripts = ts2vg=ts2vg.cli:main
4 changes: 2 additions & 2 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def linear_ts_small():

@pytest.fixture
def linear_ts_large():
return 99999999 + np.arange(0, 1_000, 0.1, dtype="float64")
return 99999999 + np.arange(0, 1_000, 0.1, dtype=np.float64)


@pytest.fixture
def linear_ts_large_negative():
return -99999999 - np.arange(0, 1_000, 0.1, dtype="float64")
return -99999999 - np.arange(0, 1_000, 0.1, dtype=np.float64)
2 changes: 1 addition & 1 deletion tests/test_horizontal.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def test_degrees(sample_ts):
np.testing.assert_array_equal(out_got, out_truth)


def test_not_built():
def test_unbuilt():
with pytest.raises(ts2vg.graph.base.NotBuiltError):
ts2vg.HorizontalVG().edges

Expand Down
4 changes: 2 additions & 2 deletions tests/test_horizontal_penetrable.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def test_penetrable_100_floating_point_linear_large_num_penetrations(linear_ts_l
m = 100

vg = ts2vg.HorizontalVG(penetrable_limit=m, weighted="num_penetrations")
out_got = vg.build(linear_ts_large).weights.sum()
out_got = sum(vg.build(linear_ts_large).weights)

# sum of num_penetrations = 0 * (n - 1) + 1 * (n - 2) + ... + m * (n - (m + 1))
out_truth = sum((i * (n - (i + 1))) for i in range(m + 1))
Expand All @@ -833,7 +833,7 @@ def test_penetrable_100_floating_point_linear_large_negative_num_penetrations(li
m = 100

vg = ts2vg.HorizontalVG(penetrable_limit=m, weighted="num_penetrations")
out_got = vg.build(linear_ts_large_negative).weights.sum()
out_got = sum(vg.build(linear_ts_large_negative).weights)

out_truth = sum((i * (n - (i + 1))) for i in range(m + 1))

Expand Down
122 changes: 118 additions & 4 deletions tests/test_natural.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,34 @@ def test_adjacency_matrix_both(sample_ts):
np.testing.assert_array_equal(out_got, out_truth)


def test_adjacency_matrix_use_weights(sample_ts):
vg = ts2vg.NaturalVG(weighted="distance").build(sample_ts)
out_got = vg.adjacency_matrix(triangle="both", use_weights=True)

out_truth = [
[np.nan, sqrt(2.0), np.nan, np.nan ],
[sqrt(2.0), np.nan, sqrt(5.0), sqrt(13.0) ],
[np.nan, sqrt(5.0), np.nan, sqrt(2.0) ],
[np.nan, sqrt(13.0), sqrt(2.0), np.nan ],
]

np.testing.assert_allclose(out_got, out_truth)


def test_adjacency_matrix_use_weights_no_weight_value(sample_ts):
vg = ts2vg.NaturalVG(weighted="distance").build(sample_ts)
out_got = vg.adjacency_matrix(triangle="both", use_weights=True, no_weight_value=-1)

out_truth = [
[-1, sqrt(2.0), -1, -1 ],
[sqrt(2.0), -1, sqrt(5.0), sqrt(13.0) ],
[-1, sqrt(5.0), -1, sqrt(2.0) ],
[-1, sqrt(13.0), sqrt(2.0), -1 ],
]

np.testing.assert_allclose(out_got, out_truth)


def test_adjacency_matrix_directed_upper(sample_ts):
vg = ts2vg.NaturalVG(directed="left_to_right").build(sample_ts)

Expand Down Expand Up @@ -429,8 +457,8 @@ def test_adjacency_matrix_directed_both(sample_ts):
np.testing.assert_array_equal(out_got, out_truth)


def test_adjacency_matrix_directed_lower(sample_ts):
vg = ts2vg.NaturalVG(directed="left_to_right")
def test_adjacency_matrix_unbuilt():
vg = ts2vg.NaturalVG()

with pytest.raises(ts2vg.graph.base.NotBuiltError):
vg.adjacency_matrix()
Expand Down Expand Up @@ -492,9 +520,95 @@ def test_degrees_out_ttb(sample_ts):
np.testing.assert_array_equal(out_got, out_truth)


def test_not_built():
def test_degrees_only_degrees(sample_ts):
vg = ts2vg.NaturalVG().build(sample_ts, only_degrees=True)
out_got = vg.degrees

out_truth = [1, 3, 2, 2]

np.testing.assert_array_equal(out_got, out_truth)


def test_degrees_in_only_degrees(sample_ts):
vg = ts2vg.NaturalVG().build(sample_ts, only_degrees=True)
out_got = vg.degrees_in

out_truth = [0, 1, 1, 2]

np.testing.assert_array_equal(out_got, out_truth)


def test_degrees_out_only_degrees(sample_ts):
vg = ts2vg.NaturalVG().build(sample_ts, only_degrees=True)
out_got = vg.degrees_out

out_truth = [1, 2, 1, 0]

np.testing.assert_array_equal(out_got, out_truth)


def test_degrees_in_ltr_only_degrees(sample_ts):
vg = ts2vg.NaturalVG(directed="left_to_right").build(sample_ts, only_degrees=True)
out_got = vg.degrees_in

out_truth = [0, 1, 1, 2]

np.testing.assert_array_equal(out_got, out_truth)


def test_degrees_out_ltr_only_degrees(sample_ts):
vg = ts2vg.NaturalVG(directed="left_to_right").build(sample_ts, only_degrees=True)
out_got = vg.degrees_out

out_truth = [1, 2, 1, 0]

np.testing.assert_array_equal(out_got, out_truth)


def test_degrees_in_ttb_only_degrees(sample_ts):
vg = ts2vg.NaturalVG(directed="top_to_bottom").build(sample_ts, only_degrees=True)
out_got = vg.degrees_in

out_truth = [1, 0, 1, 2]

np.testing.assert_array_equal(out_got, out_truth)


def test_degrees_out_ttb_only_degrees(sample_ts):
vg = ts2vg.NaturalVG(directed="top_to_bottom").build(sample_ts, only_degrees=True)
out_got = vg.degrees_out

out_truth = [0, 3, 1, 0]

np.testing.assert_array_equal(out_got, out_truth)


def test_degree_counts(sample_ts):
out_got = ts2vg.NaturalVG().build(sample_ts).degree_counts

out_truth = ([1, 2, 3], [1, 2, 1])

np.testing.assert_array_equal(out_got, out_truth)

def test_degree_distribution(sample_ts):
out_got = ts2vg.NaturalVG().build(sample_ts).degree_distribution

out_truth = ([1, 2, 3], [0.25, 0.5, 0.25])

np.testing.assert_allclose(out_got, out_truth)

def test_unbuilt():
vg = ts2vg.NaturalVG()

with pytest.raises(ts2vg.graph.base.NotBuiltError):
vg.edges


def test_unbuilt_only_degrees(sample_ts):
vg = ts2vg.NaturalVG().build(sample_ts, only_degrees=True)

with pytest.raises(ts2vg.graph.base.NotBuiltError):
ts2vg.NaturalVG().edges
vg.edges


def test_empty_ts(empty_ts):
Expand Down
Loading