Check predict, observe, and rewind raise NotFittedError before fit.
Parameters
| Name |
Type |
Description |
Default |
similarity
|
BaseSimilarity
|
|
required
|
y_pred_calib
|
DataFrame
|
A prediction frame to pass to the unfitted methods under test.
|
required
|
Raises
| Type |
Description |
AssertionError
|
If predict, observe, or rewind does not raise
NotFittedError when unfitted.
|
Source Code
View on GitHub
Source code in src/yohou/testing/similarity.py
| def check_similarity_methods_call_check_is_fitted(similarity, y_pred_calib: pl.DataFrame) -> None:
"""Check ``predict``, ``observe``, and ``rewind`` raise ``NotFittedError`` before ``fit``.
Parameters
----------
similarity : BaseSimilarity
Similarity instance.
y_pred_calib : pl.DataFrame
A prediction frame to pass to the unfitted methods under test.
Raises
------
AssertionError
If ``predict``, ``observe``, or ``rewind`` does not raise
``NotFittedError`` when unfitted.
"""
name = type(similarity).__name__
query = y_pred_calib.head(2)
unfitted = clone(similarity)
try:
unfitted.predict(query)
raise AssertionError(f"{name}.predict() must raise NotFittedError when unfitted")
except NotFittedError:
pass
unfitted2 = clone(similarity)
try:
# observe(y, y_pred, X_actual=None): both slots receive query here as a
# convenience; only the unfitted-error path is being exercised.
unfitted2.observe(query, query)
raise AssertionError(f"{name}.observe() must raise NotFittedError when unfitted")
except NotFittedError:
pass
unfitted3 = clone(similarity)
try:
# rewind(y, y_pred, X_actual=None): both slots receive query here as a
# convenience; only the unfitted-error path is being exercised.
unfitted3.rewind(query, query)
raise AssertionError(f"{name}.rewind() must raise NotFittedError when unfitted")
except NotFittedError:
pass
|