3.1.1.3. obj_tables.math package¶
3.1.1.3.1. Submodules¶
3.1.1.3.2. obj_tables.math.expression module¶
Utilities for processing mathematical expressions used by obj_tables models
- Author
Arthur Goldberg <Arthur.Goldberg@mssm.edu>
- Author
Jonathan Karr <karr@mssm.edu>
- Date
2018-12-19
- Copyright
2016-2019, Karr Lab
- License
MIT
-
class
obj_tables.math.expression.
OneToOneExpressionAttribute
(related_class, related_name='', default=None, default_cleaned_value=None, related_default=None, none_value=None, min_related=0, min_related_rev=0, verbose_name='', verbose_related_name='', description='')[source]¶ Bases:
obj_tables.core.OneToOneAttribute
Expression one-to-one attribute
- Parameters
related_class (
class
) – related classrelated_name (
str
, optional) – name of related attribute onrelated_class
default (
callable
, optional) – callable which returns default valuedefault_cleaned_value (
callable
, optional) – value to replaceNone
values with during cleaning, or function which computes the value to replaceNone
valuesrelated_default (
callable
, optional) – callable which returns default related valuenone_value (
object
, optional) – none valuemin_related (
int
, optional) – minimum number of related objects in the forward directionmin_related_rev (
int
, optional) – minimum number of related objects in the reverse directionverbose_name (
str
, optional) – verbose nameverbose_related_name (
str
, optional) – verbose related namedescription (
str
, optional) – description
-
deserialize
(value, objects, decoded=None)[source]¶ Deserialize value
- Parameters
value (
str
) – String representationobjects (
dict
) – dictionary of objects, grouped by modeldecoded (
dict
, optional) – dictionary of objects that have already been decoded
- Returns
tuple of cleaned value and cleaning error
- Return type
tuple
ofobject
,InvalidAttribute
orNone
-
get_xlsx_validation
(sheet_models=None, doc_metadata_model=None)[source]¶ Get XLSX validation
- Parameters
sheet_models (
list
ofModel
, optional) – models encoded as separate sheetsdoc_metadata_model (
type
) – model whose worksheet contains the document metadata
- Returns
validation
- Return type
wc_utils.workbook.io.FieldValidation
-
serialize
(expression, encoded=None)[source]¶ Serialize related object
- Parameters
expression (
obj_tables.Model
) – the referencedExpression
encoded (
dict
, optional) – dictionary of objects that have already been encoded
- Returns
simple Python representation
- Return type
str
-
class
obj_tables.math.expression.
ManyToOneExpressionAttribute
(related_class, related_name='', default=None, default_cleaned_value=None, related_default=[], none_value=None, min_related=0, min_related_rev=0, max_related_rev=inf, verbose_name='', verbose_related_name='', description='', related_manager=<class 'obj_tables.core.ManyToOneRelatedManager'>)[source]¶ Bases:
obj_tables.core.ManyToOneAttribute
Expression many-to-one attribute
- Parameters
related_class (
class
) – related classrelated_name (
str
, optional) – name of related attribute onrelated_class
default (
callable
, optional) – callable which returns the default valuedefault_cleaned_value (
callable
, optional) – value to replaceNone
values with during cleaning, or function which computes the value to replaceNone
valuesrelated_default (
callable
, optional) – callable which returns the default related valuenone_value (
object
, optional) – none valuemin_related (
int
, optional) – minimum number of related objects in the forward directionmin_related_rev (
int
, optional) – minimum number of related objects in the reverse directionmax_related_rev (
int
, optional) – maximum number of related objects in the reverse directionverbose_name (
str
, optional) – verbose nameverbose_related_name (
str
, optional) – verbose related namedescription (
str
, optional) – descriptionrelated_manager (
type
, optional) – related manager
-
deserialize
(value, objects, decoded=None)[source]¶ Deserialize value
- Parameters
value (
str
) – String representationobjects (
dict
) – dictionary of objects, grouped by modeldecoded (
dict
, optional) – dictionary of objects that have already been decoded
- Returns
tuple of cleaned value and cleaning error
- Return type
tuple
ofobject
,InvalidAttribute
orNone
-
get_xlsx_validation
(sheet_models=None, doc_metadata_model=None)[source]¶ Get XLSX validation
- Parameters
sheet_models (
list
ofModel
, optional) – models encoded as separate sheetsdoc_metadata_model (
type
) – model whose worksheet contains the document metadata
- Returns
validation
- Return type
wc_utils.workbook.io.FieldValidation
-
serialize
(expression, encoded=None)[source]¶ Serialize related object
- Parameters
expression (
Expression
) – the relatedExpression
encoded (
dict
, optional) – dictionary of objects that have already been encoded
- Returns
simple Python representation of the rate law expression
- Return type
str
-
class
obj_tables.math.expression.
ObjTablesTokenCodes
[source]¶ Bases:
int
,enum.Enum
ObjTablesToken codes used in parsed expressions
-
class
obj_tables.math.expression.
IdMatch
[source]¶ Bases:
tuple
IdMatch(model_type, token_pattern, match_string): Matched token pattern used by tokenize
Create new instance of IdMatch(model_type, token_pattern, match_string)
-
class
obj_tables.math.expression.
ObjTablesToken
[source]¶ Bases:
tuple
ObjTablesToken(code, token_string, model_type, model_id, model): ObjTablesToken in a parsed obj_tables expression
Create new instance of ObjTablesToken(code, token_string, model_type, model_id, model)
-
class
obj_tables.math.expression.
LexMatch
[source]¶ Bases:
tuple
LexMatch(obj_tables_tokens, num_py_tokens): container for an unambiguous Model id
Create new instance of LexMatch(obj_tables_tokens, num_py_tokens)
-
class
obj_tables.math.expression.
ExpressionTermMeta
[source]¶ Bases:
object
Metadata for subclasses that can appear in expressions
-
expression_term_token_pattern
[source]¶ token pattern for the name of the term in expression
- Type
tuple
-
expression_term_units
[source]¶ name of attribute which describes the units of the expression term
- Type
str
-
expression_term_token_pattern
= (1,)[source]
-
expression_term_units
= 'units'[source]
-
-
class
obj_tables.math.expression.
ExpressionStaticTermMeta
[source]¶ Bases:
obj_tables.math.expression.ExpressionTermMeta
Metadata for subclasses with static values that can appear in expressions
-
expression_term_value
= 'value'[source]
-
-
class
obj_tables.math.expression.
ExpressionDynamicTermMeta
[source]¶ Bases:
obj_tables.math.expression.ExpressionTermMeta
Metadata for subclasses with dynamic values that can appear in expressions
-
class
obj_tables.math.expression.
ExpressionExpressionTermMeta
[source]¶ Bases:
obj_tables.math.expression.ExpressionTermMeta
Metadata for subclasses with expressions that can appear in expressions
-
expression_term_model
= None[source]
-
-
class
obj_tables.math.expression.
Expression
[source]¶ Bases:
object
Generic methods for mathematical expressions
-
class
Meta
[source]¶ Bases:
object
Metadata for subclasses of
Expression
-
expression_term_models
[source]¶ names of classes which can appear as terms in the expression
- Type
tuple
ofstr
-
expression_valid_functions
[source]¶ Python functions which can appear in the expression
- Type
tuple
oftypes.FunctionType
-
expression_is_linear
= False[source]
-
expression_term_models
= ()[source]
-
expression_type
= None[source]
-
expression_unit_registry
= None[source]
-
expression_valid_functions
= (<class 'float'>, <built-in function fabs>, <built-in function ceil>, <built-in function floor>, <built-in function round>, <built-in function exp>, <built-in function expm1>, <built-in function pow>, <built-in function sqrt>, <built-in function log>, <built-in function log1p>, <built-in function log10>, <built-in function log2>, <built-in function factorial>, <built-in function sin>, <built-in function cos>, <built-in function tan>, <built-in function acos>, <built-in function asin>, <built-in function atan>, <built-in function atan2>, <built-in function hypot>, <built-in function degrees>, <built-in function radians>, <built-in function min>, <built-in function max>)[source]
-
-
classmethod
deserialize
(model_cls, value, objects)[source]¶ Deserialize
value
into anExpression
- Parameters
model_cls (
type
) –Expression
class or subclassvalue (
str
) – string representation of the mathematical expression, in a Python expressionobjects (
dict
) – dictionary of objects which can be used inExpression
, grouped by model
- Returns
- on error return (
None
,InvalidAttribute
), otherwise return (object in this class with instantiated
_parsed_expression
,None
)
- on error return (
- Return type
tuple
-
static
make_expression_obj
(model_type, expression, objs)[source]¶ Make an expression object
- Parameters
model_type (
type
) – anModel
that uses a mathemetical expression, likeFunction
andObservable
expression (
str
) – the expression used by themodel_type
being createdobjs (
dict
ofdict
) – all objects that are referenced inexpression
- Returns
- if successful, (
Model
,None
) containing a new instance of model_type
’s expression helper class; otherwise, (None
,InvalidAttribute
) reporting the error
- if successful, (
- Return type
tuple
-
classmethod
make_obj
(model, model_type, primary_attr, expression, objs, allow_invalid_objects=False)[source]¶ Make a model that contains an expression by using its expression helper class
For example, this uses
FunctionExpression
to make aFunction
.- Parameters
model (
Model
) – an instance ofModel
which is the root modelmodel_type (
type
) – a subclass ofModel
that uses a mathemetical expression, likeFunction
andObservable
primary_attr (
object
) – the primary attribute of themodel_type
being createdexpression (
str
) – the expression used by themodel_type
being createdobjs (
dict
ofdict
) – all objects that are referenced inexpression
allow_invalid_objects (
bool
, optional) – if set, return object - not error - if the expression object does not validate
- Returns
- a new instance of
model_type
, or, if an error occurs, an
InvalidAttribute
reporting the error
- a new instance of
- Return type
Model
orInvalidAttribute
-
merge_attrs
(other, other_objs_in_self, self_objs_in_other)[source]¶ Merge attributes of two objects
- Parameters
other (
Model
) – other modelother_objs_in_self (
dict
) – dictionary that maps instances of objects in another model to objects in a modelself_objs_in_other (
dict
) – dictionary that maps instances of objects in a model to objects in another model
-
serialize
()[source]¶ Generate string representation
- Returns
value of primary attribute
- Return type
str
-
classmethod
validate
(model_obj, parent_obj)[source]¶ Determine whether an expression model is valid
One check eval’s its deserialized expression
- Parameters
model_obj (
Expression
) – expression objectparent_obj (
Model
) – parent of expression object
- Returns
None
if the object is valid,otherwise return a list of errors in an
InvalidObject
instance
- Return type
InvalidObject
or None
-
class
-
exception
obj_tables.math.expression.
ParsedExpressionError
(message=None)[source]¶ Bases:
ValueError
Exception raised for errors in
ParsedExpression
- Parameters
message (
str
, optional) – the exception’s message
-
class
obj_tables.math.expression.
ParsedExpression
(model_cls, attr, expression, objs)[source]¶ Bases:
object
An expression in an
ObjTables
Model
These expressions are limited Python expressions with specific semantics:
They must be syntactically correct Python, except that an identifier can begin with numerical digits.
No Python keywords, strings, or tokens that do not belong in expressions are allowed.
All Python identifiers must be the primary attribute of an
ObjTables
object or the name of a function in themath
package. Objects in the model are provided in_objs
, and the allowed subset of functions inmath
must be provided in an iterator in theexpression_valid_functions
attribute of theMeta
class of a model whose whose expression is being processed.Currently (July, 2018), an identifier may refer to a
Species
,Parameter
,Reaction
,Observable
orDfbaObjReaction
.Cycles of references are illegal.
An identifier must unambiguously refer to exactly one related
Model
in a model.Each
Model
that can be used in an expression must have an ID that is an identifier, or defineexpression_term_token_pattern
as an attribute that describes theModel
’s syntactic Python structure. SeeSpecies
for an example.Every expression must be computable at any time during a simulation. The evaluation of an expression always occurs at a precise simulation time, which is implied by the expression but not explicitly represented. E.g., a reference to a
Species
means its concentration at the time the expression iseval
ed. These are the meanings of references:Species
: its current concentrationParameter
: its value, which is staticObservable
: its current value, whose units depend on its definitionReaction
: its current fluxDfbaObjReaction
: its current flux
The modeller is responsible for ensuring that units in expressions are internally consistent and appropriate for the expression’s use.
-
_py_tokens
[source]¶ a list of Python tokens generated by
tokenize.tokenize()
- Type
list
ofcollections.namedtuple
-
_objs
[source]¶ dict of obj_tables Models that might be referenced in
expression
; maps model type to a dict mapping ids to Model instances- Type
dict
-
valid_functions
[source]¶ the union of all
valid_functions
attributes for_objs
- Type
set
models that are referenced in
expression
; maps model type to dict that maps model id to model instance- Type
dict
-
lin_coeffs
[source]¶ linear coefficients of models that are referenced in
expression
; maps model type to dict that maps models to coefficients- Type
dict
-
errors
[source]¶ errors found when parsing an
expression
fails- Type
list
ofstr
-
_obj_tables_tokens
[source]¶ tokens obtained when an
expression
is successfullytokenize
d; if empty, then thisParsedExpression
cannot useeval
- Type
list
ofObjTablesToken
-
_compiled_expression_with_units
[source]¶ compiled expression with units that can be evaluated by
eval
- Type
str
-
_compiled_namespace_with_units
[source]¶ compiled namespace with units for evaluation by
eval
- Type
dict
Create an instance of ParsedExpression
- Parameters
model_cls (
type
) – theModel
which has an expressionattr (
str
) – the attribute name of the expression inmodel_cls
expression (
obj
) – the expression defined in the obj_tablesModel
objs (
dict
) – dictionary of model objects (instances ofModel
) organized by their type
- Raises
ParsedExpressionError – if
model_cls
is not a subclass ofModel
, or lexical analysis ofexpression
raises an exception, orobjs
includes model types thatmodel_cls
should not reference
-
LEGAL_TOKENS_NAMES
= ('NUMBER', 'NAME', 'LSQB', 'RSQB', 'DOT', 'COMMA', 'DOUBLESTAR', 'MINUS', 'PLUS', 'SLASH', 'STAR', 'LPAR', 'RPAR', 'EQEQUAL', 'GREATER', 'GREATEREQUAL', 'LESS', 'LESSEQUAL', 'NOTEQUAL')[source]¶
-
eval
(values, with_units=False)[source]¶ Evaluate the expression
Approach:
Ensure that the expression is compiled
Prepare namespace with model values
eval
the Python expression
- Parameters
values (
dict
) – dictionary that maps model types to dictionaries that map model ids to valueswith_units (
bool
, optional) – ifTrue
, include units
- Returns
the value of the expression
- Return type
float
,int
, orbool
- Raises
ParsedExpressionError – if the expression has not been compiled or the evaluation fails
-
get_str
(obj_tables_token_to_str, with_units=False, number_units=' * __dimensionless__')[source]¶ Generate string representation of expression, e.g. for evaluation by
eval
- Parameters
obj_tables_token_to_str (
callable
) – method to get string representation of a token that represents an instance ofModel
.with_units (
bool
, optional) – ifTrue
, include unitsnumber_units (
str
, optional) – default units for numbers
- Returns
string representation of expression
- Return type
str
- Raises
ParsedExpressionError – if the expression is invalid
-
recreate_whitespace
(expr)[source]¶ Insert the whitespace in this object’s
expression
into an expression with the same token countUsed to migrate an expression to a different set of model type names.
- Parameters
expr (
str
) – a syntactically correct Python expression- Returns
expr
with the whitespace in this instance’sexpression
inserted betweenits Python tokens
- Return type
str
- Raises
ParsedExpressionError – if tokenizing
expr
raises an exception, or ifexpr
doesn’t have the same number of Python tokens asself.expression
-
test_eval
(values=1.0, with_units=False)[source]¶ Test evaluate this
ParsedExpression
with the value of all models given byvalues
This is used to validate this
ParsedExpression
, as well as for testing.- Parameters
values (
float
ordict
, optional) – value(s) of models used by the test evaluation; if a scalar, then that value is used for all models; if adict
then it maps model types to their values, or it maps model types to dictionaries that map model ids to the values of individual models used in the testwith_units (
bool
, optional) – ifTrue
, evaluate units
- Returns
the value of the expression
- Return type
float
,int
, orbool
- Raises
ParsedExpressionError – if the expression evaluation fails
-
tokenize
(case_fold_match=False)[source]¶ Tokenize a Python expression in
self.expression
- Parameters
case_fold_match (
bool
, optional) – if set, casefold identifiers before matching; identifier keys inself._objs
must already be casefold’ed; default = False- Returns
list
: ofObjTablesToken
sdict
: dict of Model instances used by this list, grouped by Model typelist
ofstr
: list of errors
- Return type
tuple
- Raises
ParsedExpressionError – if
model_cls
does not have aMeta
attribute
-
class
obj_tables.math.expression.
LinearParsedExpressionValidator
[source]¶ Bases:
object
Verify whether a
ParsedExpression
is equivalent to a linear function of variablesA linear function of identifiers has the form a1 * v1 + a2 * v2 + … an * vn, where a1 … an are floats or integers and v1 … vn are variables.
-
is_linear
[source]¶ whether the
ParsedExpression
is linear- Type
boolean
-
opaque_ids
[source]¶ map from Model ids that are not valid Python identifiers to opaque ids
- Type
dict
-
VALID_NOTE_TYPES
= {<class '_ast.Name'>, <class '_ast.Sub'>, <class '_ast.Add'>, <class '_ast.Load'>, <class '_ast.Num'>, <class '_ast.USub'>, <class '_ast.Constant'>, <class '_ast.UAdd'>, <class '_ast.UnaryOp'>, <class '_ast.Mult'>, <class '_ast.BinOp'>}[source]¶
-
get_cls_and_model
(id)[source]¶ Get the class and instance of a related model with id id
- Parameters
id (
str
) – id- Returns
(:obj:`type
,Model
)`: the class and instance of a related model with id id- Return type
tuple
- Raises
ParsedExpressionError – if multiple related models have id id
-
validate
(parsed_expression, set_linear_coeffs=True)[source]¶ Determine whether the expression is a valid linear expression
- Parameters
parsed_expression (
ParsedExpression
) – a parsed expressionset_linear_coeffs (
boolean
, optional) – ifTrue
:, set the linear coefficients for the related objects
- Returns
(False, error)
ifself.expression
does not represent a linear expression,or
(True, None)
if it does
- Return type
tuple
-
3.1.1.3.3. obj_tables.math.numeric module¶
Math attributes
- Author
Jonathan Karr <karr@mssm.edu>
- Date
2017-05-10
- Copyright
2017, Karr Lab
- License
MIT
-
class
obj_tables.math.numeric.
ArrayAttribute
(min_length=0, max_length=inf, default=None, none_value=None, verbose_name='', description='', primary=False, unique=False)[source]¶ Bases:
obj_tables.core.LiteralAttribute
numpy.ndarray attribute
- Parameters
min_length (
int
, optional) – minimum lengthmax_length (
int
, optional) – maximum lengthdefault (
numpy.array
, optional) – default valuenone_value (
object
, optional) – none valueverbose_name (
str
, optional) – verbose namedescription (
str
, optional) – descriptionprimary (
bool
, optional) – indicate if attribute is primary attributeunique (
bool
, optional) – indicate if attribute value must be unique
-
deserialize
(value)[source]¶ Deserialize value
- Parameters
value (
str
) – semantically equivalent representation- Returns
tuple of cleaned value and cleaning error
- Return type
tuple
ofnumpy.array
,core.InvalidAttribute
orNone
-
from_builtin
(json)[source]¶ Decode a simple Python representation (dict, list, str, float, bool, None) of a value of the attribute that is compatible with JSON and YAML
- Parameters
json (
list
) – simple Python representation of a value of the attribute- Returns
decoded value of the attribute
- Return type
numpy.array
-
serialize
(value)[source]¶ Serialize string
- Parameters
value (
numpy.array
) – Python representation- Returns
simple Python representation
- Return type
str
-
to_builtin
(value)[source]¶ Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML
- Parameters
value (
numpy.array
) – value of the attribute- Returns
simple Python representation of a value of the attribute
- Return type
list
-
validate
(obj, value)[source]¶ Determine if
value
is a valid value- Parameters
obj (
Model
) – class being validatedvalue (
numpy.array
) – value of attribute to validate
- Returns
- None if attribute is valid, other return
list of errors as an instance of
core.InvalidAttribute
- Return type
core.InvalidAttribute
or None
-
validate_unique
(objects, values)[source]¶ Determine if the attribute values are unique
- Parameters
objects (
list
ofModel
) – list ofModel
objectsvalues (
list
ofnumpy.array
) – list of values
- Returns
- None if values are unique, otherwise return a
list of errors as an instance of
core.InvalidAttribute
- Return type
core.InvalidAttribute
or None
-
class
obj_tables.math.numeric.
TableAttribute
(default=None, none_value=None, verbose_name='', description='', primary=False, unique=False)[source]¶ Bases:
obj_tables.core.LiteralAttribute
pandas.DataFrame attribute
- Parameters
default (
pandas.DataFrame
, optional) – default valuenone_value (
object
, optional) – none valueverbose_name (
str
, optional) – verbose namedescription (
str
, optional) – descriptionprimary (
bool
, optional) – indicate if attribute is primary attributeunique (
bool
, optional) – indicate if attribute value must be unique
-
deserialize
(value)[source]¶ Deserialize value
- Parameters
value (
str
) – semantically equivalent representation- Returns
tuple of cleaned value and cleaning error
- Return type
tuple
ofpandas.DataFrame
,core.InvalidAttribute
orNone
-
from_builtin
(json)[source]¶ Decode a simple Python representation (dict, list, str, float, bool, None) of a value of the attribute that is compatible with JSON and YAML
- Parameters
json (
dict
) – simple Python representation of a value of the attribute- Returns
decoded value of the attribute
- Return type
pandas.DataFrame
-
serialize
(value)[source]¶ Serialize string
- Parameters
value (
pandas.DataFrame
) – Python representation- Returns
simple Python representation
- Return type
str
-
to_builtin
(value)[source]¶ Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML
- Parameters
value (
pandas.DataFrame
) – value of the attribute- Returns
simple Python representation of a value of the attribute
- Return type
dict
-
validate
(obj, value)[source]¶ Determine if
value
is a valid value- Parameters
obj (
Model
) – class being validatedvalue (
pandas.DataFrame
) – value of attribute to validate
- Returns
- None if attribute is valid, other return list of
errors as an instance of
core.InvalidAttribute
- Return type
core.InvalidAttribute
or None
-
validate_unique
(objects, values)[source]¶ Determine if the attribute values are unique
- Parameters
objects (
list
ofModel
) – list ofModel
objectsvalues (
list
ofpandas.DataFrame
) – list of values
- Returns
- None if values are unique, otherwise return a
list of errors as an instance of
core.InvalidAttribute
- Return type
core.InvalidAttribute
or None
3.1.1.3.4. obj_tables.math.symbolic module¶
Attributes for symbolic math
- Author
Jonathan Karr <karr@mssm.edu>
- Date
2017-05-10
- Copyright
2017, Karr Lab
- License
MIT
-
class
obj_tables.math.symbolic.
SymbolicBasicAttribute
(sympy_type=<class 'sympy.core.basic.Basic'>, default=None, none_value=None, verbose_name='', description='', primary=False, unique=False, unique_case_insensitive=False)[source]¶ Bases:
obj_tables.core.LiteralAttribute
Base class for SymPy expression, symbol attributes
-
sympy_type
[source]¶ attribute type (e.g.
sympy.Basic
,sympy.Expr
,sympy.Symbol
)- Type
sympy.core.assumptions.ManagedProperties
- Parameters
sympy_type (
sympy.core.assumptions.ManagedProperties
, optional) – attribute type (e.g.sympy.Basic
,sympy.Expr
,sympy.Symbol
)default (
sympy.Basic
, optional) – default valuenone_value (
object
, optional) – none valueverbose_name (
str
, optional) – verbose namedescription (
str
, optional) – descriptionprimary (
bool
, optional) – indicate if attribute is primary attributeunique (
bool
, optional) – indicate if attribute value must be uniqueunique_case_insensitive (
bool
, optional) – if true, conduct case-insensitive test of uniqueness
-
deserialize
(value)[source]¶ Deserialize value
- Parameters
value (
str
) – semantically equivalent representation- Returns
tuple of cleaned value and cleaning error
- Return type
tuple
ofsympy.Basic
,core.InvalidAttribute
orNone
-
from_builtin
(json)[source]¶ Decode a simple Python representation (dict, list, str, float, bool, None) of a value of the attribute that is compatible with JSON and YAML
- Parameters
json (
list
) – simple Python representation of a value of the attribute- Returns
decoded value of the attribute
- Return type
sympy.Basic
-
serialize
(value)[source]¶ Serialize string
- Parameters
value (
sympy.Basic
) – Python representation- Returns
simple Python representation
- Return type
str
-
to_builtin
(value)[source]¶ Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML
- Parameters
value (
sympy.Basic
) – value of the attribute- Returns
simple Python representation of a value of the attribute
- Return type
str
-
validate
(obj, value)[source]¶ Determine if
value
is a valid value- Parameters
obj (
Model
) – class being validatedvalue (
sympy.Basic
) – value of attribute to validate
- Returns
- None if attribute is valid, other return list of errors
as an instance of
core.InvalidAttribute
- Return type
core.InvalidAttribute
or None
-
validate_unique
(objects, values)[source]¶ Determine if the attribute values are unique
- Parameters
objects (
list
ofModel
) – list ofModel
objectsvalues (
list
ofsympy.Basic
) – list of values
- Returns
- None if values are unique, otherwise return a list
of errors as an instance of
core.InvalidAttribute
- Return type
core.InvalidAttribute
or None
-
-
class
obj_tables.math.symbolic.
SymbolicSymbolAttribute
(default=None, none_value=None, verbose_name='', description='', primary=False, unique=False, unique_case_insensitive=False)[source]¶ Bases:
obj_tables.math.symbolic.SymbolicBasicAttribute
SymPy symbol attribute
- Parameters
default (
sympy.Symbol
, optional) – default valuenone_value (
object
, optional) – none valueverbose_name (
str
, optional) – verbose namedescription (
str
, optional) – descriptionprimary (
bool
, optional) – indicate if attribute is primary attributeunique (
bool
, optional) – indicate if attribute value must be uniqueunique_case_insensitive (
bool
, optional) – if true, conduct case-insensitive test of uniqueness
-
serialize
(value)[source]¶ Serialize string
- Parameters
value (
sympy.Symbol
) – Python representation- Returns
simple Python representation
- Return type
str
-
to_builtin
(value)[source]¶ Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML
- Parameters
value (
sympy.Symbol
) – value of the attribute- Returns
simple Python representation of a value of the attribute
- Return type
str
-
class
obj_tables.math.symbolic.
SymbolicExprAttribute
(default=None, none_value=None, verbose_name='', description='', primary=False, unique=False, unique_case_insensitive=False)[source]¶ Bases:
obj_tables.math.symbolic.SymbolicBasicAttribute
SymPy expression attribute
- Parameters
default (
sympy.Expr
, optional) – default valuenone_value (
object
, optional) – none valueverbose_name (
str
, optional) – verbose namedescription (
str
, optional) – descriptionprimary (
bool
, optional) – indicate if attribute is primary attributeunique (
bool
, optional) – indicate if attribute value must be uniqueunique_case_insensitive (
bool
, optional) – if true, conduct case-insensitive test of uniqueness
-
serialize
(value)[source]¶ Serialize string
- Parameters
value (
sympy.Expr
) – Python representation- Returns
simple Python representation
- Return type
str
-
to_builtin
(value)[source]¶ Encode a value of the attribute using a simple Python representation (dict, list, str, float, bool, None) that is compatible with JSON and YAML
- Parameters
value (
sympy.Expr
) – value of the attribute- Returns
simple Python representation of a value of the attribute
- Return type
str