|
32 | 32 | WeibullCDFAdstock,
|
33 | 33 | WeibullPDFAdstock,
|
34 | 34 | adstock_from_dict,
|
35 |
| - register_adstock_transformation, |
36 |
| -) |
37 |
| -from pymc_marketing.mmm.components.adstock import ( |
38 |
| - ADSTOCK_TRANSFORMATIONS, |
39 | 35 | )
|
40 | 36 | from pymc_marketing.mmm.transformers import ConvMode
|
41 | 37 | from pymc_marketing.prior import Prior
|
@@ -161,27 +157,25 @@ def test_adstock_from_dict_without_priors(adstock, deserialize_func) -> None:
|
161 | 157 | }
|
162 | 158 |
|
163 | 159 |
|
164 |
| -@pytest.mark.parametrize("deserialize_func", [adstock_from_dict, deserialize]) |
165 |
| -def test_register_adstock_transformation(deserialize_func) -> None: |
166 |
| - class NewTransformation(AdstockTransformation): |
167 |
| - lookup_name: str = "new_transformation" |
168 |
| - default_priors = {} |
| 160 | +class AnotherNewTransformation(AdstockTransformation): |
| 161 | + lookup_name: str = "another_new_transformation" |
| 162 | + default_priors = {} |
169 | 163 |
|
170 |
| - def function(self, x): |
171 |
| - return x |
| 164 | + def function(self, x): |
| 165 | + return x |
172 | 166 |
|
173 |
| - register_adstock_transformation(NewTransformation) |
174 |
| - assert "new_transformation" in ADSTOCK_TRANSFORMATIONS |
175 | 167 |
|
| 168 | +@pytest.mark.parametrize("deserialize_func", [adstock_from_dict, deserialize]) |
| 169 | +def test_automatic_register_adstock_transformation(deserialize_func) -> None: |
176 | 170 | data = {
|
177 |
| - "lookup_name": "new_transformation", |
| 171 | + "lookup_name": "another_new_transformation", |
178 | 172 | "l_max": 10,
|
179 | 173 | "normalize": False,
|
180 | 174 | "mode": "Before",
|
181 | 175 | "priors": {},
|
182 | 176 | }
|
183 | 177 | adstock = deserialize_func(data)
|
184 |
| - assert adstock == NewTransformation( |
| 178 | + assert adstock == AnotherNewTransformation( |
185 | 179 | l_max=10, mode=ConvMode.Before, normalize=False, priors={}
|
186 | 180 | )
|
187 | 181 |
|
@@ -239,3 +233,22 @@ def test_deserialization(
|
239 | 233 | assert isinstance(alpha, ArbitraryObject)
|
240 | 234 | assert alpha.msg == "hello"
|
241 | 235 | assert alpha.value == 1
|
| 236 | + |
| 237 | + |
| 238 | +def test_deserialize_new_transformation() -> None: |
| 239 | + class NewAdstock(AdstockTransformation): |
| 240 | + lookup_name = "new_adstock" |
| 241 | + |
| 242 | + def function(self, x): |
| 243 | + return x |
| 244 | + |
| 245 | + default_priors = {} |
| 246 | + |
| 247 | + data = { |
| 248 | + "lookup_name": "new_adstock", |
| 249 | + "l_max": 10, |
| 250 | + } |
| 251 | + |
| 252 | + instance = deserialize(data) |
| 253 | + assert isinstance(instance, NewAdstock) |
| 254 | + assert instance.l_max == 10 |
0 commit comments