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

Raise informative error when including target in X #962

Merged
merged 4 commits into from
Aug 22, 2024
Merged
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: 4 additions & 0 deletions pymc_marketing/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@
self._generate_and_preprocess_model_data(X, y_df.values.flatten())
if self.X is None or self.y is None:
raise ValueError("X and y must be set before calling build_model!")
if self.output_var in X.columns:
raise ValueError(

Check warning on line 552 in pymc_marketing/model_builder.py

View check run for this annotation

Codecov / codecov/patch

pymc_marketing/model_builder.py#L552

Added line #L552 was not covered by tests
f"X includes a column named '{self.output_var}', which conflicts with the target variable."
)

if not hasattr(self, "model"):
self.build_model(self.X, self.y)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ def test_fit_no_t(toy_X):
assert "posterior" in model_builder.idata.groups()


@pytest.mark.xfail
def test_fit_dup_Y(toy_X):
# create redundant target column in X
toy_X = pd.concat((toy_X, toy_y), axis=1)
model_builder = ModelBuilderTest()
model_builder.fit(X=toy_X, chains=1, draws=100, tune=100)


@pytest.mark.skipif(
sys.platform == "win32",
reason="Permissions for temp files not granted on windows CI.",
Expand Down
Loading