Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove abstract method of data_setter #1463

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pymc_marketing/clv/models/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,3 @@ def output_var(self):
def _generate_and_preprocess_model_data(self, *args, **kwargs):
"""Generate and preprocess model data."""
pass

def _data_setter(self):
"""Set the data for the model."""
pass
27 changes: 15 additions & 12 deletions pymc_marketing/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@
else:
return check_array(X, accept_sparse=False)

@abstractmethod
def _data_setter(
self,
X: np.ndarray | pd.DataFrame,
Expand All @@ -219,21 +218,25 @@
y : array, shape (n_obs,)
The target values (real numbers).

Returns
-------
None

Examples
--------
>>> def _data_setter(self, data : pd.DataFrame):
>>> with self.model:
>>> pm.set_data({'x': X['x'].values})
>>> try: # if y values in new data
>>> pm.set_data({'y_data': y.values})
>>> except: # dummies otherwise
>>> pm.set_data({'y_data': np.zeros(len(data))})
Example logic of data_setter method

.. code-block:: python

def _data_setter(self, X, y=None):

data = {"X": X}
if y is None:
y = np.zeros(len(X))
data["y"] = y

with self.model:
pm.set_data(data)

"""
msg = "This model doesn't support setting new data, posterior_predictive, or out of sample methods."
raise NotImplementedError(msg)

Check warning on line 239 in pymc_marketing/model_builder.py

View check run for this annotation

Codecov / codecov/patch

pymc_marketing/model_builder.py#L238-L239

Added lines #L238 - L239 were not covered by tests

@property
@abstractmethod
Expand Down
3 changes: 0 additions & 3 deletions tests/test_model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,6 @@ def __init__(
super().__init__(model_config=model_config, sampler_config=sampler_config)
self.new_parameter = new_parameter

def _data_setter(self, X: pd.DataFrame, y: pd.Series = None) -> None:
pass

def build_model(self, X: pd.DataFrame, y: pd.Series, model_config=None) -> None:
with pm.Model() as self.model:
intercept = pm.Normal("intercept")
Expand Down