valarray 0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. valarray/__init__.py +6 -0
  2. valarray/core/__init__.py +27 -0
  3. valarray/core/array.py +121 -0
  4. valarray/core/array_type_adapter.py +109 -0
  5. valarray/core/axes_and_fields.py +127 -0
  6. valarray/core/comparisons.py +71 -0
  7. valarray/core/errors_exceptions/__init__.py +41 -0
  8. valarray/core/errors_exceptions/error_list.py +87 -0
  9. valarray/core/errors_exceptions/exceptions.py +75 -0
  10. valarray/core/errors_exceptions/generic.py +57 -0
  11. valarray/core/errors_exceptions/validation_errors/__init__.py +0 -0
  12. valarray/core/errors_exceptions/validation_errors/array_creation.py +14 -0
  13. valarray/core/errors_exceptions/validation_errors/axes.py +68 -0
  14. valarray/core/errors_exceptions/validation_errors/base.py +26 -0
  15. valarray/core/errors_exceptions/validation_errors/dtype.py +60 -0
  16. valarray/core/errors_exceptions/validation_errors/values.py +99 -0
  17. valarray/core/types/__init__.py +24 -0
  18. valarray/core/types/generics.py +40 -0
  19. valarray/core/types/other.py +23 -0
  20. valarray/core/utils.py +89 -0
  21. valarray/core/validation_functions/__init__.py +20 -0
  22. valarray/core/validation_functions/array.py +62 -0
  23. valarray/core/validation_functions/array_values.py +47 -0
  24. valarray/core/validation_functions/dtype.py +44 -0
  25. valarray/core/validation_functions/field_values/__init__.py +0 -0
  26. valarray/core/validation_functions/field_values/core.py +106 -0
  27. valarray/core/validation_functions/field_values/types_and_data_structures.py +90 -0
  28. valarray/core/validation_functions/field_values/utils.py +143 -0
  29. valarray/core/validation_functions/shape.py +67 -0
  30. valarray/core/validation_functions/utils.py +24 -0
  31. valarray/core/validators/__init__.py +13 -0
  32. valarray/core/validators/base.py +72 -0
  33. valarray/core/validators/value_comparisons.py +107 -0
  34. valarray/numpy/__init__.py +24 -0
  35. valarray/numpy/array.py +63 -0
  36. valarray/numpy/array_type_adapter.py +133 -0
  37. valarray/numpy/axes_and_fields.py +83 -0
  38. valarray/numpy/comparisons.py +135 -0
  39. valarray/numpy/errors_exceptions.py +172 -0
  40. valarray/numpy/types.py +32 -0
  41. valarray/numpy/validation_functions.py +170 -0
  42. valarray/numpy/validators.py +35 -0
  43. valarray-0.4.dist-info/METADATA +698 -0
  44. valarray-0.4.dist-info/RECORD +45 -0
  45. valarray-0.4.dist-info/WHEEL +4 -0
@@ -0,0 +1,170 @@
1
+ """
2
+ *import* `validate_array` **function**
3
+
4
+ *import* `validate_dtype` **function**
5
+
6
+ *import* `validate_shape` **function**
7
+
8
+ *import* `validate_array_values` **function**
9
+
10
+ *import* `validate_field_values` **function**
11
+ """
12
+
13
+ from types import EllipsisType
14
+ from typing import Any, Literal, Sequence, overload
15
+
16
+ import numpy as np
17
+ import numpy.typing as npt
18
+
19
+ from valarray.core.errors_exceptions import (
20
+ IncorrectAxNumberError,
21
+ IncorrectAxSizesError,
22
+ IncorrectDTypeError,
23
+ InvalidArrayValuesError,
24
+ InvalidFieldValuesError,
25
+ ValidationError,
26
+ ValidationErrorList,
27
+ )
28
+ from valarray.core.validation_functions import validate_array as core_validate_array
29
+ from valarray.core.validation_functions import (
30
+ validate_array_values as core_validate_array_values,
31
+ )
32
+ from valarray.core.validation_functions import validate_dtype as core_validate_dtype
33
+ from valarray.core.validation_functions import (
34
+ validate_field_values as core_validate_field_values,
35
+ )
36
+ from valarray.core.validation_functions import validate_shape as core_validate_shape
37
+ from valarray.core.validators import Validator
38
+
39
+ from .array_type_adapter import NumpyArrayTypeAdapter
40
+ from .axes_and_fields import AxesTuple
41
+ from .types import AdvancedIndex, NumpyDTypeT
42
+ from .validators import NumpyValidator
43
+
44
+
45
+ def validate_dtype(
46
+ arr: npt.NDArray[Any], dtypelike: npt.DTypeLike | EllipsisType
47
+ ) -> ValidationErrorList[IncorrectDTypeError[npt.DTypeLike, np.dtype]]:
48
+ """Validate that numpy array has the correct dtype.
49
+
50
+ Args:
51
+ arr (npt.NDArray[Any]): Array to be validated.
52
+ dtypelike (npt.DTypeLike | EllipsisType): Expected datatype
53
+ (if `...` , do not validate).
54
+
55
+ Returns:
56
+ errs (ValidationErrorList[IncorrectDTypeError[npt.DTypeLike, np.dtype]]):
57
+ list containing a single dtype error or an empty list.
58
+
59
+ (introduced ***v0.1***, last_modified ***v0.4***)
60
+ """
61
+ return core_validate_dtype(arr, dtypelike, NumpyArrayTypeAdapter())
62
+
63
+
64
+ validate_shape = core_validate_shape
65
+
66
+
67
+ def validate_array_values(
68
+ arr: npt.NDArray[NumpyDTypeT],
69
+ validators: Sequence[NumpyValidator[NumpyDTypeT]],
70
+ ) -> ValidationErrorList[
71
+ InvalidArrayValuesError[npt.NDArray[NumpyDTypeT], AdvancedIndex]
72
+ ]:
73
+ """Validate numpy array with a sequence of validators applied to the whole array
74
+ and return potential errors.
75
+
76
+ Args:
77
+ arr (npt.NDArray[NumpyDTypeT]: Array to be validated.
78
+ validators (Sequence[NumpyValidator[NumpyDTypeT]]: Validators to apply.
79
+
80
+ Returns:
81
+ errs (ValidationErrorList[InvalidArrayValuesError[npt.NDArray[NumpyDTypeT], AdvancedIndex]]):
82
+ List containing at most 1 error per validator.
83
+
84
+ (introduced ***v0.3***, last_modified ***v0.4***)
85
+ """
86
+ return core_validate_array_values(arr, validators, NumpyArrayTypeAdapter())
87
+
88
+
89
+ @overload
90
+ def validate_field_values(
91
+ arr: npt.NDArray[NumpyDTypeT],
92
+ schema: AxesTuple[NumpyDTypeT] | EllipsisType,
93
+ check_shape: Literal[False] = False,
94
+ ) -> ValidationErrorList[
95
+ InvalidFieldValuesError[npt.NDArray[NumpyDTypeT], AdvancedIndex]
96
+ ]: ...
97
+
98
+
99
+ @overload
100
+ def validate_field_values(
101
+ arr: npt.NDArray[NumpyDTypeT],
102
+ schema: AxesTuple[NumpyDTypeT] | EllipsisType,
103
+ check_shape: Literal[True] = True,
104
+ ) -> (
105
+ ValidationErrorList[
106
+ InvalidFieldValuesError[npt.NDArray[NumpyDTypeT], AdvancedIndex]
107
+ ]
108
+ | ValidationErrorList[IncorrectAxNumberError | IncorrectAxSizesError]
109
+ ): ...
110
+
111
+
112
+ def validate_field_values(
113
+ arr: npt.NDArray[NumpyDTypeT],
114
+ schema: AxesTuple[NumpyDTypeT] | EllipsisType,
115
+ check_shape: bool = False,
116
+ ) -> (
117
+ ValidationErrorList[
118
+ InvalidFieldValuesError[npt.NDArray[NumpyDTypeT], AdvancedIndex]
119
+ ]
120
+ | ValidationErrorList[IncorrectAxNumberError | IncorrectAxSizesError]
121
+ ):
122
+ """Validate numpy array fields with validators defined in schema and return potential errors.
123
+
124
+ Args:
125
+ arr (npt.NDArray[NumpyDTypeT]): Array to be validated.
126
+ schema (AxesTuple | EllipsisType):
127
+ Array schema (if `...` , do not validate).
128
+ check_shape (bool, optional): If `True`, check shape with `validate_shape()` first.
129
+ Defaults to False.
130
+
131
+ Returns:
132
+ errs (ValidationErrorList[InvalidFieldValuesError[npt.NDArray[NumpyDTypeT], AdvancedIndex]]):
133
+ List containing at most 1 error per validator
134
+ (including built-in field value comparisons like `gt`, `lt` etc.).
135
+
136
+ (introduced ***v0.4***)
137
+ """
138
+ return core_validate_field_values(arr, schema, NumpyArrayTypeAdapter(), check_shape)
139
+
140
+
141
+ def validate_array(
142
+ arr: npt.NDArray[NumpyDTypeT],
143
+ dtypelike: npt.DTypeLike | EllipsisType,
144
+ schema: AxesTuple[NumpyDTypeT] | EllipsisType,
145
+ validators: Sequence[Validator[npt.NDArray[NumpyDTypeT], AdvancedIndex]],
146
+ ) -> ValidationErrorList[ValidationError]:
147
+ """Validate array:
148
+ - data type
149
+ - shape (based on array schema)
150
+ - array values (using a sequence of validators)
151
+ - field values (based on validators defined in array schema)
152
+
153
+ First validate data type and shape. If those are correct, validate field and array values.
154
+
155
+ Args:
156
+ arr (npt.NDArray[NumpyDTypeT]): Array to be validated.
157
+ dtypelike (npt.DTypeLike | EllipsisType,): Expected datatype (if `...` , do not validate).
158
+ schema (AxesTuple[NumpyDTypeT] | EllipsisType):
159
+ Expected array schema (if `...` , do not validate).
160
+ validators (Sequence[Validator[npt.NDArray[NumpyDTypeT], AdvancedIndex]]):
161
+ Validators to apply.
162
+
163
+ Returns:
164
+ ValidationErrorList[ValidationError]: Validation errors.
165
+
166
+ (introduced ***v0.4***)
167
+ """
168
+ return core_validate_array(
169
+ arr, dtypelike, schema, validators, NumpyArrayTypeAdapter()
170
+ )
@@ -0,0 +1,35 @@
1
+ from abc import abstractmethod
2
+ from typing import Generic, Optional
3
+
4
+ import numpy.typing as npt
5
+
6
+ from valarray.core.validators import ValidationResult, Validator
7
+
8
+ from .types import AdvancedIndex, NumpyDTypeT
9
+
10
+
11
+ class NumpyValidator(
12
+ Validator[npt.NDArray[NumpyDTypeT], AdvancedIndex], Generic[NumpyDTypeT]
13
+ ):
14
+ """Base class for numpy array Validators.
15
+
16
+ Type variables:
17
+ - `NumpyDTypeT` - data type of array to be validated.
18
+
19
+ Subclasses need to implement:
20
+ **abstract method**
21
+ - `validate` -
22
+ Method to validate an array.
23
+
24
+ Subclasses can optionally implement:
25
+ **abstract method**
26
+ - `__str__` -
27
+ String representation of validator used in error messages.
28
+ If not implemented defalts to class name.
29
+
30
+ (introduced ***v0.3***)"""
31
+
32
+ @abstractmethod
33
+ def validate(
34
+ self, arr: npt.NDArray[NumpyDTypeT]
35
+ ) -> Optional[bool | ValidationResult[AdvancedIndex]]: ...