diff --git a/.flake8 b/.flake8 index 5ff4b7c..5c3d2ba 100644 --- a/.flake8 +++ b/.flake8 @@ -4,7 +4,11 @@ count = True max-line-length = 88 extend-ignore = E203 exclude = + .venv, + venv, .vscode, .conda, + .venv, + tests.venv/, .hatch, __pycache__ \ No newline at end of file diff --git a/bdms/mutators.py b/bdms/mutators.py index 162ff7a..99fb0e3 100644 --- a/bdms/mutators.py +++ b/bdms/mutators.py @@ -200,6 +200,8 @@ def __init__( f"Transition matrix {transition_matrix} is not a valid stochastic" " matrix." ) + if (not len(transition_matrix) == 1) and np.diag(transition_matrix).any(): + raise ValueError("transition_matrix diagonal must be zero.") super().__init__(attr=attr) self.state_space = state_space self.state_space_idxs: dict[Any, int] = { diff --git a/bdms/poisson.py b/bdms/poisson.py index 0b4f794..22d6934 100644 --- a/bdms/poisson.py +++ b/bdms/poisson.py @@ -196,6 +196,8 @@ class ConstantProcess(HomogeneousProcess): def __init__(self, value: float = 1.0): super().__init__() self.value = value + if self.value < 0: + raise ValueError("The constant rate must be a non-negative float") def λ_homogeneous( self, x: Hashable | Sequence[Hashable] | NDArray[Any] @@ -216,6 +218,14 @@ def __init__( self, rates: Mapping[Hashable, float] | Sequence[float], attr: str = "state" ): super().__init__(attr=attr) + if isinstance(rates, Mapping): + for rate in rates.values(): + if rate < 0.0: + raise ValueError("The rate for each state must be >= 0") + else: + for rate in rates: + if rate < 0.0: + raise ValueError("The rate for each state must be >= 0") self.rates = rates def λ_homogeneous( diff --git a/pyproject.toml b/pyproject.toml index 7365981..a692a4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,8 @@ packages = ["bdms"] [tool.hatch.version] path = "bdms/__init__.py" + + # this puts hatch envs in a .hatch directory, so vscode can find them @@ -102,3 +104,6 @@ format = [ "black .", "docformatter --black --in-place **/*.py", ] + +[tool.flake8] +exclude = ".venv,venv" \ No newline at end of file