Skip to content

Commit 723887a

Browse files
migrate to Data and non-mutable coords (#816)
Co-authored-by: Juan Orduz <[email protected]>
1 parent 03e9215 commit 723887a

File tree

6 files changed

+12
-22
lines changed

6 files changed

+12
-22
lines changed

pymc_marketing/clv/models/pareto_nbd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ def build_model(self) -> None: # type: ignore[override]
240240
"purchase_covariate": self.purchase_covariate_cols,
241241
"dropout_covariate": self.dropout_covariate_cols,
242242
"obs_var": ["recency", "frequency"],
243+
"customer_id": self.data["customer_id"],
243244
}
244-
mutable_coords = {"customer_id": self.data["customer_id"]}
245-
with pm.Model(coords=coords, coords_mutable=mutable_coords) as self.model:
245+
with pm.Model(coords=coords) as self.model:
246246
if self.purchase_covariate_cols:
247-
purchase_data = pm.MutableData(
247+
purchase_data = pm.Data(
248248
"purchase_data",
249249
self.data[self.purchase_covariate_cols],
250250
dims=["customer_id", "purchase_covariate"],
@@ -273,7 +273,7 @@ def build_model(self) -> None: # type: ignore[override]
273273

274274
# churn priors
275275
if self.dropout_covariate_cols:
276-
dropout_data = pm.MutableData(
276+
dropout_data = pm.Data(
277277
"dropout_data",
278278
self.data[self.dropout_covariate_cols],
279279
dims=["customer_id", "dropout_covariate"],

pymc_marketing/mmm/delayed_saturated_mmm.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,9 @@ def _generate_and_preprocess_model_data( # type: ignore
203203
date_data = X[self.date_column]
204204
channel_data = X[self.channel_columns]
205205

206-
self.coords_mutable: dict[str, Any] = {
207-
"date": date_data,
208-
}
209206
coords: dict[str, Any] = {
210207
"channel": self.channel_columns,
208+
"date": date_data,
211209
}
212210

213211
new_X_dict = {
@@ -349,20 +347,17 @@ def build_model(
349347
self._generate_and_preprocess_model_data(X, y)
350348
with pm.Model(
351349
coords=self.model_coords,
352-
coords_mutable=self.coords_mutable,
353350
) as self.model:
354351
channel_data_ = pm.Data(
355352
name="channel_data",
356353
value=self.preprocessed_data["X"][self.channel_columns],
357354
dims=("date", "channel"),
358-
mutable=True,
359355
)
360356

361357
target_ = pm.Data(
362358
name="target",
363359
value=self.preprocessed_data["y"],
364360
dims="date",
365-
mutable=True,
366361
)
367362
if self.time_varying_intercept | self.time_varying_media:
368363
time_index = pm.Data(
@@ -443,7 +438,6 @@ def build_model(
443438
name="control_data",
444439
value=self.preprocessed_data["X"][self.control_columns],
445440
dims=("date", "control"),
446-
mutable=True,
447441
)
448442

449443
control_contributions = pm.Deterministic(
@@ -461,7 +455,6 @@ def build_model(
461455
self.date_column
462456
].dt.dayofyear.to_numpy(),
463457
dims="date",
464-
mutable=True,
465458
)
466459

467460
def create_deterministic(x: pt.TensorVariable) -> None:
@@ -546,7 +539,6 @@ def channel_contributions_forward_pass(
546539
"""
547540
coords = {
548541
**self.model_coords,
549-
**self.coords_mutable,
550542
}
551543
with pm.Model(coords=coords):
552544
pm.Deterministic(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies = [
3131
"numpy>=1.17",
3232
"pandas",
3333
# NOTE: Used as minimum pymc version with ci.yml `OLDEST_PYMC_VERSION`
34-
"pymc>=5.12.0,<5.16.0",
34+
"pymc>=5.13.0,<5.16.0",
3535
"scikit-learn>=1.1.1",
3636
"seaborn>=0.12.2",
3737
"xarray",

tests/clv/test_distributions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def test_pareto_nbd_sample_prior(
261261
s = pm.Gamma(name="s", alpha=5, beta=1, size=s_size)
262262
beta = pm.Gamma(name="beta", alpha=5, beta=1, size=beta_size)
263263

264-
T = pm.MutableData(name="T", value=np.array(10))
264+
T = pm.Data(name="T", value=np.array(10))
265265

266266
ParetoNBD(
267267
name="pareto_nbd",
@@ -436,7 +436,7 @@ def test_beta_geo_beta_binom_sample_prior(
436436
gamma = pm.Normal(name="gamma", mu=gamma_true, sigma=1e-4, size=gamma_size)
437437
delta = pm.Normal(name="delta", mu=delta_true, sigma=1e-4, size=delta_size)
438438

439-
T = pm.MutableData(name="T", value=np.array(T_true))
439+
T = pm.Data(name="T", value=np.array(T_true))
440440

441441
BetaGeoBetaBinom(
442442
name="beta_geo_beta_binom",

tests/mmm/test_lift_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,13 @@ def test_add_lift_measurements_before_new_data(
325325
channels = ["organic", "paid", "social"]
326326
coords = {
327327
"channel": channels,
328-
}
329-
coords_mutable = {
330328
"date": ["2020-01-01", "2020-01-02", "2020-01-03"],
331329
}
332-
with pm.Model(coords=coords, coords_mutable=coords_mutable) as model:
330+
with pm.Model(coords=coords) as model:
333331
alpha = pm.HalfNormal("alpha", dims="channel")
334332
lam = pm.HalfNormal("lam", dims="channel")
335333

336-
X = pm.Data("X", np.ones((3, 3)), dims=("date", "channel"), mutable=True)
334+
X = pm.Data("X", np.ones((3, 3)), dims=("date", "channel"))
337335
pm.Deterministic(
338336
"random_operation",
339337
X + alpha + lam,

tests/test_model_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def build_model(self, X: pd.DataFrame, y: pd.Series, model_config=None):
110110
with pm.Model(coords=coords) as self.model:
111111
if model_config is None:
112112
model_config = self.default_model_config
113-
x = pm.MutableData("x", self.X["input"].values)
114-
y_data = pm.MutableData("y_data", self.y)
113+
x = pm.Data("x", self.X["input"].values)
114+
y_data = pm.Data("y_data", self.y)
115115

116116
# prior parameters
117117
a_loc = model_config["a"]["loc"]

0 commit comments

Comments
 (0)