Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .github/workflows/pypi_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ jobs:
file_path.write_text(new_text)

update_file("pyproject.toml", r'^version = ".*"$', f'version = "{version}"')
update_file("setup.py", r"version='[^']*'", f"version='{version}'")
PY
git status --short

Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
python-version: ${{ matrix.python-version }}
- name: Install package and test dependencies
run: |
python -m pip install --upgrade pip
pip install numpy scipy matplotlib
- name: Test with pytest
pip install -e .[dev]
- name: Test with pytest (unit tests + docstring examples)
run: |
pip install pytest pytest-cov
pytest tests/* --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html

pytest --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov=pba --cov-report=xml
29 changes: 22 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
# Scratch / local
test.py
pba/__pycache__
setup.txt
.DS_Store
.vscode

# Virtual environments
.pyenv/
lib/
bin/
pyvenv.cfg
*.pyc
.vscode
.pyenv/
dist/*

pba.egg-info/
setup.txt
# Python byte-compiled / caches
__pycache__/
*.py[cod]
.pytest_cache/

# Build / packaging artifacts
build/
dist/
*.egg-info/
*.egg

# Coverage / test reports
.coverage
coverage.xml
htmlcov/
junit/
10 changes: 0 additions & 10 deletions MANIFEST

This file was deleted.

24 changes: 24 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Pytest configuration.

Injects the common PBA names into the namespace used to run docstring
examples (``--doctest-modules``) so that examples written as they would be
typed at an interactive prompt (e.g. ``>>> pba.Interval(0, 1)``) execute
without an explicit import line. This keeps the documentation examples
runnable and verified in CI.
"""

import pytest


@pytest.fixture(autouse=True)
def _add_doctest_namespace(doctest_namespace):
import numpy as np

import pba

doctest_namespace["pba"] = pba
doctest_namespace["np"] = np
doctest_namespace["Interval"] = pba.Interval
doctest_namespace["Pbox"] = pba.Pbox
doctest_namespace["Logical"] = pba.Logical
12 changes: 9 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
# -- Project information -----------------------------------------------------

project = 'PBA-for-python'
copyright = '2023, Nick Gray'
copyright = '2023-2026, Nick Gray'
author = 'Nick Gray'

# The full version, including alpha/beta/rc tags
release = 'v0.16.2'
# The full version, including alpha/beta/rc tags. Sourced from the installed
# package metadata so it stays in sync with pyproject.toml.
try:
from importlib.metadata import version as _version

release = _version("pba")
except Exception:
release = "0.0.0"


# -- General configuration ---------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions pba/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version("pba")
except PackageNotFoundError: # running from a source checkout that isn't installed
__version__ = "0.0.0+unknown"

from .interval import *
from .pbox import *
from .cbox import *
from .copula import *
from .core import *
from .logical import *
Expand Down
2 changes: 1 addition & 1 deletion pba/cbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from matplotlib import pyplot as plt
from typing import List, Tuple, Union

__all__ = ["Cbox"]
__all__ = ["Cbox", "singh"]


class Cbox(Pbox):
Expand Down
17 changes: 9 additions & 8 deletions pba/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import numpy as np
import warnings

__all__ = ["envelope", "env", "sum", "mean", "mul", "sqrt"]


def envelope(*args: Union[Interval, Pbox, float]) -> Union[Interval, Pbox]:
"""
Expand Down Expand Up @@ -116,14 +118,14 @@ def sum(*args: Union[list, tuple], method="f"):
"""

if len(args) == 1:
if isinstance(args[0], [list, tuple, np.ndarray]):
if isinstance(args[0], (list, tuple, np.ndarray)):
args = args[0]
else:
return args[0]

s = 0
for o in args:
if isinstance(o, [Interval, Pbox, Cbox]):
if isinstance(o, (Interval, Pbox, Cbox)):
s = o.add(s, method=method)
else:
s += o
Expand All @@ -148,7 +150,9 @@ def mean(*args: Union[list, tuple], method="f"):

Implemented as

>>> pba.sum(*args,method = method)/len(args)
.. code-block:: python

pba.sum(*args, method=method) / len(args)

"""
s = sum(*args, method=method)
Expand Down Expand Up @@ -189,11 +193,8 @@ def mul(*args, method=None):
def sqrt(a):
if a.__class__.__name__ == "Interval":
return Interval(np.sqrt(a.left), np.sqrt(a.right))
elif a.__class__.__name__ == "PBox":
return Pbox(
left=np.sqrt(a.left),
right=np.sqrt(a.right),
)
elif isinstance(a, Pbox):
return a.sqrt()
else:

return np.sqrt(a)
Loading
Loading