cis_interface.metaschema.properties package

Submodules

cis_interface.metaschema.properties.ArrayMetaschemaProperties module

class cis_interface.metaschema.properties.ArrayMetaschemaProperties.LengthMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Property class for ‘length’ property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘length’ 1darray property.

name = 'length'
python_types = (<class 'unyt.array.unyt_array'>, <class 'numpy.ndarray'>)
schema = {'description': 'Number of elements in the 1D array.', 'minimum': 1, 'type': 'number'}
types = ('1darray',)
class cis_interface.metaschema.properties.ArrayMetaschemaProperties.ShapeMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Property class for ‘shape’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparison method for the ‘shape’ ndarray property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘shape’ ndarray property.

name = 'shape'
python_types = (<class 'unyt.array.unyt_array'>, <class 'numpy.ndarray'>)
schema = {'description': 'Shape of the ND array in each dimension.', 'items': {'minimum': 1, 'type': 'integer'}, 'type': 'array'}
types = ('ndarray',)

cis_interface.metaschema.properties.DefaultProperty module

class cis_interface.metaschema.properties.DefaultProperty.DefaultMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Property class for ‘default’ property.

name = 'default'
classmethod normalize(normalizer, value, instance, schema)[source]

Normalization method for ‘default’ property.

cis_interface.metaschema.properties.JSONArrayMetaschemaProperties module

class cis_interface.metaschema.properties.JSONArrayMetaschemaProperties.ItemsMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Property class for ‘items’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparison method for ‘items’ container property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘items’ container property.

name = 'items'
python_types = (<class 'pandas.core.frame.DataFrame'>, <class 'tuple'>, <class 'list'>, <class 'numpy.ndarray'>)
types = ('array',)

cis_interface.metaschema.properties.JSONObjectMetaschemaProperties module

class cis_interface.metaschema.properties.JSONObjectMetaschemaProperties.PropertiesMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Property class for ‘properties’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparison method for ‘properties’ container property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘properties’ container property.

name = 'properties'
classmethod normalize(validator, value, instance, schema)[source]

Normalization method for ‘properties’ container property.

classmethod post_validate(validator, value, instance, schema)[source]

Actions performed after validation if normalizing.

python_types = (<class 'dict'>,)
types = ('object',)

cis_interface.metaschema.properties.MetaschemaProperty module

class cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty[source]

Bases: object

Base class for adding properties to the metaschema.

name

Name of the property.

Type:str
schema

JSON schema describing valid values for the property.

Type:dict
types

Types of instances that the property is valid for.

Type:list
python_types

Python types of instances that the property is valid for.

Type:list
classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Method to determine compatiblity of one property value with another. This method is not necessarily symmetric in that the second value may not be compatible with the first even if the first is compatible with the second.

Parameters:
  • prop1 (object) – Property value to compare against prop2.
  • prop2 (object) – Property value to compare against.
Yields:

str – Comparision failure messages.

classmethod encode(instance, typedef=None)[source]

Method to encode the property given the object.

Parameters:
  • instance (object) – Object to get property for.
  • typedef (object, None) – Template value in type definition to use for initializing encoding some cases. Defaults to None and is ignored.
Returns:

Encoded property for instance.

Return type:

object

name = 'base'
classmethod normalize(validator, value, instance, schema)[source]

Method to normalize the instance based on the property value.

Parameters:
  • validator (Validator) – Validator class.
  • value (object) – Property value.
  • instance (object) – Object to normalize.
  • schema (dict) – Schema containing this property.
Returns:

Normalized object.

Return type:

object

classmethod normalize_in_schema(schema)[source]

Method to normalize the entry for this property in a schema.

Parameters:schema (dict) – Schema to normalize.
Returns:Normalized schema.
Return type:dict
classmethod post_validate(validator, value, instance, schema)[source]

Actions performed after validation if normalizing.

python_types = ()
schema = None
types = ()
classmethod validate(validator, value, instance, schema)[source]

Validator for JSON schema validation of an instance by this property. If there is not a user provided validate function, the instance will be encoded and then the encoded value will be checked against the provided value using cls.compare.

Parameters:
  • validator (jsonschmea.Validator) – JSON schema validator.
  • value (object) – Value of the property in the schema.
  • instance (object) – Instance to validate.
  • schema (dict) – Schema that instance should be validated against.
Yields:

str – Error messages associated with failed validation.

classmethod wrapped_validate(validator, value, instance, schema)[source]

Wrapped validator that handles errors produced by the native validate method and ensures that the property is parsed by the base validator and raises the correct error if necessary.

Parameters:
  • *args – All arguments are passed to the validate class method.
  • **kwargs – All keyword arguments are passed to the validate class method.
cis_interface.metaschema.properties.MetaschemaProperty.create_property(name, schema, encode, validate=None, compare=None)[source]

Create a new property class.

Parameters:
  • name (str) – Name of the property.
  • schema (dict) – JSON schema describing valid values for the property.
  • encode (function) – Function to encode the property based on a provided instance. The function must take an instance as input and return the value of the property for that instance.
  • validate (function, optional) – Function to determine if an instance is valid under the contraint of this property. The function must take as input a jsonschema validator, a property value, an instance to evaluate, and the schema. The function must return a boolean: True if the instance is valid, False otherwise. See cls.validate for additional information and default behavior.
  • compare (function, optional) – Function to determine if two property values are compatible. The function must take as input two property values and return a boolean: True if the first property is compatible with the second, False otherwise. See cls.compare for additional information and default behavior.

cis_interface.metaschema.properties.ScalarMetaschemaProperties module

class cis_interface.metaschema.properties.ScalarMetaschemaProperties.PrecisionMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Property class for ‘precision’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparison for the ‘precision’ scalar property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘precision’ scalar property.

name = 'precision'
classmethod normalize_in_schema(schema)[source]

Normalization for the ‘precision’ scalar property in a schema.

python_types = (<class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'numpy.signedinteger'>, <class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'unyt.array.unyt_array'>, <class 'numpy.int64'>, <class 'bytes'>, <class 'str'>, <class 'numpy.str_'>, <class 'float'>, <class 'numpy.unsignedinteger'>, <class 'int'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'unyt.array.unyt_quantity'>, <class 'numpy.ndarray'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'complex'>, <class 'numpy.uint16'>, <class 'numpy.int16'>)
schema = {'description': 'The size (in bits) of each item.', 'minimum': 1, 'type': 'number'}
types = ('scalar', 'ndarray', 'unicode', 'float', 'bytes', '1darray', 'uint', 'int', 'complex')
class cis_interface.metaschema.properties.ScalarMetaschemaProperties.SubtypeMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Property class for ‘subtype’ property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘subtype’ scalar property.

name = 'subtype'
classmethod normalize_in_schema(schema)[source]

Normalization for the ‘subtype’ scalar property in a schema.

python_types = (<class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'numpy.signedinteger'>, <class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'unyt.array.unyt_array'>, <class 'numpy.int64'>, <class 'bytes'>, <class 'str'>, <class 'numpy.str_'>, <class 'float'>, <class 'numpy.unsignedinteger'>, <class 'int'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'unyt.array.unyt_quantity'>, <class 'numpy.ndarray'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'complex'>, <class 'numpy.uint16'>, <class 'numpy.int16'>)
schema = {'description': 'The base type for each item.', 'enum': ['bytes', 'complex', 'float', 'int', 'uint', 'unicode'], 'type': 'string'}
types = ('scalar', 'ndarray', '1darray')
class cis_interface.metaschema.properties.ScalarMetaschemaProperties.UnitsMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Property class for ‘units’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparision for the ‘units’ scalar property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘units’ scalar property.

name = 'units'
python_types = (<class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'numpy.signedinteger'>, <class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'unyt.array.unyt_array'>, <class 'numpy.int64'>, <class 'bytes'>, <class 'str'>, <class 'numpy.str_'>, <class 'float'>, <class 'numpy.unsignedinteger'>, <class 'int'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'unyt.array.unyt_quantity'>, <class 'numpy.ndarray'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'complex'>, <class 'numpy.uint16'>, <class 'numpy.int16'>)
schema = {'description': 'Physical units.', 'type': 'string'}
types = ('scalar', 'ndarray', 'unicode', 'float', 'bytes', '1darray', 'uint', 'int', 'complex')
cis_interface.metaschema.properties.ScalarMetaschemaProperties.data2dtype(data)[source]

Get numpy data type for an object.

Parameters:data (object) – Python object.
Returns:Numpy data type.
Return type:np.dtype
cis_interface.metaschema.properties.ScalarMetaschemaProperties.definition2dtype(props)[source]

Get numpy data type for a type definition.

Parameters:props (dict) – Type definition properties.
Returns:Numpy data type.
Return type:np.dtype

cis_interface.metaschema.properties.TitleMetaschemaProperty module

class cis_interface.metaschema.properties.TitleMetaschemaProperty.TitleMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Title property with validation of new properties.

name = 'title'
python_types = (<class 'pandas.core.frame.DataFrame'>, <class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'numpy.signedinteger'>, <class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'unyt.array.unyt_array'>, <class 'numpy.int64'>, <class 'bytes'>, <class 'str'>, <class 'numpy.str_'>, <class 'float'>, <class 'numpy.unsignedinteger'>, <class 'method'>, <class 'builtin_function_or_method'>, <class 'function'>, <class 'dict'>, <class 'int'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'tuple'>, <class 'numpy.int8'>, <class 'numpy.ndarray'>, <class 'unyt.array.unyt_quantity'>, <class 'numbers.Number'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'complex'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'list'>, <class 'NoneType'>, <class 'bool'>)
types = ('scalar', 'ndarray', 'unicode', 'boolean', 'float', 'bytes', 'null', 'number', '1darray', 'string', 'uint', 'int', 'function', 'object', 'complex', 'array', 'integer')

cis_interface.metaschema.properties.TypeMetaschemaProperty module

class cis_interface.metaschema.properties.TypeMetaschemaProperty.TypeMetaschemaProperty[source]

Bases: cis_interface.metaschema.properties.MetaschemaProperty.MetaschemaProperty

Type property with validation of new properties.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Method to determine compatiblity of one property value with another. This method is not necessarily symmetric in that the second value may not be compatible with the first even if the first is compatible with the second.

Parameters:
  • prop1 (object) – Property value to compare against prop2.
  • prop2 (object) – Property value to compare against.
Yields:

str – Comparision failure messages.

classmethod encode(instance, typedef=None)[source]

Method to encode the property given the object.

Parameters:
  • instance (object) – Object to get property for.
  • typedef (object, None) – Template value in type definition to use for initializing encoding some cases. Defaults to None and is ignored.
Returns:

Encoded property for instance.

Return type:

object

name = 'type'
classmethod normalize(normalizer, value, instance, schema)[source]

Method to normalize the instance based on the property value.

Parameters:
  • normalizer (Normalizer) – Normalizer class.
  • value (object) – Property value.
  • instance (object) – Object to normalize.
  • schema (dict) – Schema containing this property.
Returns:

Normalized object.

Return type:

object

python_types = (<class 'pandas.core.frame.DataFrame'>, <class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'numpy.signedinteger'>, <class 'cis_interface.metaschema.datatypes.ObjMetaschemaType.ObjDict'>, <class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'unyt.array.unyt_array'>, <class 'numpy.int64'>, <class 'bytes'>, <class 'str'>, <class 'numpy.str_'>, <class 'float'>, <class 'numpy.unsignedinteger'>, <class 'cis_interface.metaschema.datatypes.PlyMetaschemaType.PlyDict'>, <class 'method'>, <class 'builtin_function_or_method'>, <class 'function'>, <class 'dict'>, <class 'int'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'tuple'>, <class 'numpy.int8'>, <class 'numpy.ndarray'>, <class 'unyt.array.unyt_quantity'>, <class 'numbers.Number'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'complex'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'list'>, <class 'NoneType'>, <class 'bool'>)
types = ('scalar', 'ndarray', 'unicode', 'boolean', 'float', 'bytes', 'schema', 'number', '1darray', 'ply', 'string', 'obj', 'uint', 'int', 'array', 'function', 'object', 'complex', 'null', 'integer')

Module contents

cis_interface.metaschema.properties.get_metaschema_property(property_name, skip_generic=False)[source]

Get the property class associated with a metaschema property.

Parameters:
  • property_name (str) – Name of property to get class for.
  • skip_generic (bool, optional) – If True and the property dosn’t have a class, None is returned. Defaults to False.
Returns:

Associated property class.

Return type:

MetaschemaProperty

cis_interface.metaschema.properties.get_registered_properties()[source]

Return a dictionary of registered properties.

Returns:Registered property/class pairs.
Return type:dict
cis_interface.metaschema.properties.import_all_properties()[source]

Import all types to ensure they are registered.

cis_interface.metaschema.properties.register_metaschema_property(prop_class)[source]

Register a schema property.

Parameters:

prop_class (class) – Class to be registered.

Raises:
  • ValueError – If a property class has already been registered under the same name.
  • ValueError – If the base validator already has a validator function for the property and the new property class has a schema defined.
  • ValueError – If the base validator already has a validator function for the property and the validate method on the new property class is not disabled.
  • ValueError – If the property class does not have an entry in the existing metaschema.