VariableSchema#

class pymc_marketing.data.idata.schema.VariableSchema(**data)[source]#

Schema for a single variable in InferenceData.

Validates the structure (dimensions and dtype) of xarray.DataArray variables within InferenceData groups.

Parameters:
namestr

Variable name

requiredbool, default True

Whether this variable must be present

dimstuple of str or “*”

Expected dimension names. Use “*” to accept any dimensions.

dtypestr, tuple of str, or None

Expected numpy dtype(s) (e.g., “float64”, “int64”, or (“float64”, “int64”)). Use None to skip dtype validation.

descriptionstr, default “”

Human-readable description of this variable

Examples

>>> schema = VariableSchema(
...     name="channel_contribution",
...     dims=("date", "channel"),
...     dtype="float64",
...     required=True,
... )
>>> data_array = xr.DataArray(...)
>>> errors = schema.validate_variable(data_array)
>>> if errors:
...     print("Validation errors:", errors)

Methods

VariableSchema.__init__(**data)

Create a new model by parsing and validating input data from keyword arguments.

VariableSchema.construct([_fields_set])

VariableSchema.copy(*[, include, exclude, ...])

Returns a copy of the model.

VariableSchema.dict(*[, include, exclude, ...])

VariableSchema.from_orm(obj)

VariableSchema.json(*[, include, exclude, ...])

VariableSchema.model_construct([_fields_set])

Creates a new instance of the Model class with validated data.

VariableSchema.model_copy(*[, update, deep])

!!! abstract "Usage Documentation"

VariableSchema.model_dump(*[, mode, ...])

!!! abstract "Usage Documentation"

VariableSchema.model_dump_json(*[, indent, ...])

!!! abstract "Usage Documentation"

VariableSchema.model_json_schema([by_alias, ...])

Generates a JSON schema for a model class.

VariableSchema.model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

VariableSchema.model_post_init(context, /)

Override this method to perform additional initialization after __init__ and model_construct.

VariableSchema.model_rebuild(*[, force, ...])

Try to rebuild the pydantic-core schema for the model.

VariableSchema.model_validate(obj, *[, ...])

Validate a pydantic model instance.

VariableSchema.model_validate_json(json_data, *)

!!! abstract "Usage Documentation"

VariableSchema.model_validate_strings(obj, *)

Validate the given object with string data against the Pydantic model.

VariableSchema.parse_file(path, *[, ...])

VariableSchema.parse_obj(obj)

VariableSchema.parse_raw(b, *[, ...])

VariableSchema.schema([by_alias, ref_template])

VariableSchema.schema_json(*[, by_alias, ...])

VariableSchema.update_forward_refs(**localns)

VariableSchema.validate(value)

VariableSchema.validate_variable(data_array)

Validate variable structure.

Attributes

model_computed_fields

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_extra

Get extra fields set during validation.

model_fields

model_fields_set

Returns the set of fields that have been explicitly set on this model instance.

name

required

dims

dtype

description