@@ -28,7 +28,7 @@ class NotLoaded:
28
28
29
29
# the implementation of the class below is inspired by the 'ConstrainedBytes' class
30
30
# from the types.py module of the 'pydantic' library
31
- class ConstrainedArrayImpl (Array ):
31
+ class CheckedArrayImpl (Array ):
32
32
expected_axes : AxisCollection
33
33
dtype : np .dtype = np .dtype (float )
34
34
@@ -73,10 +73,10 @@ def validate(cls, value, field: ModelField):
73
73
# the implementation of the function below is inspired by the 'conbytes' function
74
74
# from the types.py module of the 'pydantic' library
75
75
76
- def ConstrainedArray (axes : AxisCollection , dtype : np .dtype = float ) -> Type [Array ]:
76
+ def CheckedArray (axes : AxisCollection , dtype : np .dtype = float ) -> Type [Array ]:
77
77
# XXX: for a very weird reason I don't know, I have to put the fake import below
78
78
# to get autocompletion from PyCharm
79
- from larray .core .constrained import ConstrainedArrayImpl
79
+ from larray .core .checked import CheckedArrayImpl
80
80
"""
81
81
Represents a constrained array.
82
82
Its axes are assumed to be "frozen", meaning they are constant all along the execution of the program.
@@ -98,13 +98,13 @@ def ConstrainedArray(axes: AxisCollection, dtype: np.dtype = float) -> Type[Arra
98
98
axes = AxisCollection (axes )
99
99
_dtype = np .dtype (dtype )
100
100
101
- class ConstrainedArrayValue ( ConstrainedArrayImpl ):
101
+ class CheckedArrayValue ( CheckedArrayImpl ):
102
102
expected_axes = axes
103
103
dtype = _dtype
104
104
105
- return ConstrainedArrayValue
105
+ return CheckedArrayValue
106
106
107
- class AbstractConstrainedSession :
107
+ class AbstractCheckedSession :
108
108
pass
109
109
110
110
# Simplified version of the ModelMetaclass class from pydantic:
@@ -125,7 +125,7 @@ def __new__(mcs, name, bases, namespace, **kwargs):
125
125
validators : Dict [str , List [Validator ]] = {}
126
126
127
127
for base in reversed (bases ):
128
- if issubclass (base , AbstractConstrainedSession ) and base != AbstractConstrainedSession :
128
+ if issubclass (base , AbstractCheckedSession ) and base != AbstractCheckedSession :
129
129
config = inherit_config (base .__config__ , config )
130
130
fields .update (deepcopy (base .__fields__ ))
131
131
validators = inherit_validators (base .__validators__ , validators )
@@ -147,7 +147,7 @@ def __new__(mcs, name, bases, namespace, **kwargs):
147
147
# extract and build fields
148
148
class_vars = set ()
149
149
if (namespace .get ('__module__' ), namespace .get ('__qualname__' )) != \
150
- ('larray.core.constrained ' , 'ConstrainedSession ' ):
150
+ ('larray.core.checked ' , 'CheckedSession ' ):
151
151
untouched_types = UNTOUCHED_TYPES + config .keep_untouched
152
152
153
153
# annotation only fields need to come first in fields
@@ -190,12 +190,12 @@ def __new__(mcs, name, bases, namespace, **kwargs):
190
190
}
191
191
return super ().__new__ (mcs , name , bases , new_namespace , ** kwargs )
192
192
193
- class ConstrainedSession (Session , AbstractConstrainedSession , metaclass = ModelMetaclass ):
193
+ class CheckedSession (Session , AbstractCheckedSession , metaclass = ModelMetaclass ):
194
194
"""
195
195
This class is intended to be inherited by user defined classes in which the variables of a model are declared.
196
196
Each declared variable is constrained by a type defined explicitly or deduced from the given default value
197
197
(see examples below).
198
- All classes inheriting from `ConstrainedSession ` will have access to all methods of the
198
+ All classes inheriting from `CheckedSession ` will have access to all methods of the
199
199
:py:class:`Session` class.
200
200
201
201
The special :py:funct:`ConstantAxesArray` type represents an Array object with constant axes.
@@ -207,7 +207,7 @@ class ConstrainedSession(Session, AbstractConstrainedSession, metaclass=ModelMet
207
207
to enter after only a few characters have been typed).
208
208
209
209
As for normal Session objects, it is still possible to add undeclared variables to instances of
210
- classes inheriting from `ConstrainedSession ` but this must be done with caution.
210
+ classes inheriting from `CheckedSession ` but this must be done with caution.
211
211
212
212
Parameters
213
213
----------
@@ -223,8 +223,8 @@ class ConstrainedSession(Session, AbstractConstrainedSession, metaclass=ModelMet
223
223
224
224
Warnings
225
225
--------
226
- The :py:method:`ConstrainedSession .filter`, :py:method:`ConstrainedSession .compact`
227
- and :py:method:`ConstrainedSession .apply` methods return a simple Session object.
226
+ The :py:method:`CheckedSession .filter`, :py:method:`CheckedSession .compact`
227
+ and :py:method:`CheckedSession .apply` methods return a simple Session object.
228
228
The type of the declared variables (and the value for the declared constants) will
229
229
no longer be checked.
230
230
@@ -246,7 +246,7 @@ class ConstrainedSession(Session, AbstractConstrainedSession, metaclass=ModelMet
246
246
247
247
Content of file 'model.py'
248
248
249
- >>> class ModelVariables(ConstrainedSession ):
249
+ >>> class ModelVariables(CheckedSession ):
250
250
... # --- declare variables with defined types ---
251
251
... # Their values will be defined at runtime but must match the specified type.
252
252
... variant_name: str
@@ -260,10 +260,10 @@ class ConstrainedSession(Session, AbstractConstrainedSession, metaclass=ModelMet
260
260
... # --- declare constrained arrays ---
261
261
... # the constrained arrays have axes assumed to be "frozen", meaning they are
262
262
... # constant all along the execution of the program.
263
- ... mortality_rate: ConstrainedArray ((AGE, GENDER))
263
+ ... mortality_rate: CheckedArray ((AGE, GENDER))
264
264
... # for constrained arrays, the default value can be given as a scalar.
265
265
... # A dtype can be also optionally specified (defaults to float).
266
- ... deaths: ConstrainedArray ((AGE, GENDER, TIME), dtype=int) = 0
266
+ ... deaths: CheckedArray ((AGE, GENDER, TIME), dtype=int) = 0
267
267
268
268
>>> variant_name = 'variant_1'
269
269
>>> # instantiation --> create an instance of the ModelVariables class
@@ -455,9 +455,9 @@ def dict(self, exclude: Set[str] = None):
455
455
del d [name ]
456
456
return d
457
457
458
- class Parameters (ConstrainedSession ):
458
+ class Parameters (CheckedSession ):
459
459
"""
460
- Same as py:class:`ConstrainedSession ` but declared variables cannot be modified after initialization.
460
+ Same as py:class:`CheckedSession ` but declared variables cannot be modified after initialization.
461
461
462
462
Parameters
463
463
----------
@@ -473,7 +473,7 @@ class Parameters(ConstrainedSession):
473
473
474
474
See Also
475
475
--------
476
- ConstrainedSession
476
+ CheckedSession
477
477
478
478
Examples
479
479
--------
@@ -513,12 +513,12 @@ class Config:
513
513
allow_mutation = False
514
514
515
515
else :
516
- def ConstrainedArray (axes : AxisCollection , dtype : np .dtype = float ) -> Type [Array ]:
517
- raise NotImplementedError ("ConstrainedArray cannot be used because pydantic is not installed" )
516
+ def CheckedArray (axes : AxisCollection , dtype : np .dtype = float ) -> Type [Array ]:
517
+ raise NotImplementedError ("CheckedArray cannot be used because pydantic is not installed" )
518
518
519
- class ConstrainedSession (object ):
519
+ class CheckedSession (object ):
520
520
def __init__ (self , * args , ** kwargs ):
521
- raise NotImplementedError ("ConstrainedSession class cannot be instantiated "
521
+ raise NotImplementedError ("CheckedSession class cannot be instantiated "
522
522
"because pydantic is not installed" )
523
523
524
524
class Parameters (object ):
0 commit comments