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_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

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