Skip to content

Commit

Permalink
inline check for correct data index
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusSagen committed Nov 2, 2023
1 parent 87ebb29 commit 705ae8b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions pymc_marketing/mmm/validating.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
]


def _has_valid_indices(df: pd.DataFrame) -> bool:
return (
isinstance(df.index, pd.RangeIndex)
and df.index.start == 0
and df.index.stop == len(df)
)


def validation_method_y(method: Callable) -> Callable:
if not hasattr(method, "_tags"):
method._tags = {} # type: ignore
Expand Down Expand Up @@ -49,7 +41,11 @@ def validate_date_col(self, data: pd.DataFrame) -> None:
if self.date_column not in data.columns:
raise ValueError(f"date_col {self.date_column} not in data")

if not _has_valid_indices(data):
if (
not isinstance(data.index, pd.RangeIndex)
or data.index.start != 0
or data.index.stop != len(data)
):
raise ValueError(
"X or y has incorrect indices. Try to reset with `data.reset_index(inplace=True)`"
)
Expand Down

0 comments on commit 705ae8b

Please sign in to comment.