Skip to content

Add type annotations on input and return values#73

Open
einarwar wants to merge 1 commit into
equinor:mainfrom
einarwar:add-type-annotations
Open

Add type annotations on input and return values#73
einarwar wants to merge 1 commit into
equinor:mainfrom
einarwar:add-type-annotations

Conversation

@einarwar

@einarwar einarwar commented Nov 7, 2025

Copy link
Copy Markdown

Closes #72

This PR adds type annotations for all input arguments and return values for all functions and methods.

I might not have gotten the correct types in all functions, so please correct me if there is anything wrong. There is currently limited typing capabilities in numpy out of the box, but saying if it is a 1d array (np.ndarray[tuple[int], np.float64]) or 2D-array (np.ndarray[tuple[int, int], np.float64]) is pretty valuable, so i added a new file called types.py to contain typing constructs. I also added some string literals for various functions/methods that accept only certian string values.

Comment thread pyproject.toml
dev = [
"ruff",
"pytest",
"typing-extensions>=4.15.0",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing.Self was not added until python 3.11, so to be able to support 3.10 this dependency is needed

Comment thread src/probabilit/types.py
CorrelationType = Literal["pearson", "spearman"]
CorrelatorType = Literal["cholesky", "imanconover", "permutation", "composite"]
SamplingMethodType = Literal["lhs", "halton", "sobol"]
DistributionType = Literal[

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list is probably longer, i just added the types i found being used in the repo

Comment on lines -33 to +45
import numpy as np
import scipy as sp
import abc
import dataclasses

import contextlib
import os
import dataclasses
import itertools
import os
from collections.abc import Iterable, Iterator
from typing import Any

import numpy as np
import scipy as sp
from typing_extensions import Self

from probabilit.types import Array1D, Array2D, CorrelationType

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that my IDE automatically sorted the imports. I see you already are using ruff, so it might be a good idea to enable the I (isort) rule as well

@einarwar einarwar force-pushed the add-type-annotations branch from 772ada5 to d29cff8 Compare January 2, 2026 10:55
@einarwar einarwar force-pushed the add-type-annotations branch 2 times, most recently from efe976f to 280c90d Compare May 4, 2026 14:09
@einarwar

einarwar commented May 4, 2026

Copy link
Copy Markdown
Author

@tommyod i updated this recently. Please let me know if you want to reduce the amount of type annotations to just public functions

@einarwar einarwar force-pushed the add-type-annotations branch from 280c90d to fd0d0b3 Compare May 4, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type annotations

1 participant