align_posterior_dim#

pymc_marketing.pytensor_utils.align_posterior_dim(name, posterior_da, dim, bound)[source]#

Check dim’s labels against bound and reorder the axis to them.

A dimension labeled on one side only cannot be checked, and a duplicated layout label could not be realigned by sel – it would silently pick one column twice – so both are refused. An unlabeled dimension, or one whose labels already match, keeps its labels in the bound order.

Parameters:
  • name (str) – The posterior variable, named in the error.

  • posterior_da (DataArray) – The variable to align.

  • dim (str) – The dimension to check and reorder.

  • bound (Index | None) – The labels dim was constructed with, or None when it had none.

Return type:

xr.DataArray

Returns:

posterior_da with dim in the order of bound, or unchanged when dim is unlabeled on both sides.

Raises:

ValueError – If dim is labeled on one side only, bound holds a duplicated label, or the two label sets differ in length or content.