Skip to content

Commit

Permalink
👽 Add a fit method to MelusineTransformer and BaseMelusineDetector
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoPerrier committed Dec 10, 2024
1 parent 084fbe7 commit 4529ca1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
34 changes: 34 additions & 0 deletions melusine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ def parse_column_list(columns: str | Iterable[str]) -> list[str]:
columns = [columns]
return list(columns)

def fit(self, X: MelusineDataset, y: Any = None) -> MelusineTransformer:
"""A reference implementation of a fitting function.
Parameters
----------
X : The training input samples.
y : The target values (class labels in classification, real numbers in
regression).
Returns
-------
self : object
Returns self.
"""
return self

def transform(self, data: MelusineDataset) -> MelusineDataset:
"""
Transform input data.
Expand Down Expand Up @@ -196,6 +213,23 @@ def transform_methods(self) -> list[Callable]:
List of methods to be called by the transform method.
"""

def fit(self, X: MelusineDataset, y: Any = None) -> MelusineTransformer:
"""A reference implementation of a fitting function.
Parameters
----------
X : The training input samples.
y : The target values (class labels in classification, real numbers in
regression).
Returns
-------
self : object
Returns self.
"""
return self

def transform(self, df: MelusineDataset) -> MelusineDataset:
"""
Re-definition of super().transform() => specific detector's implementation
Expand Down
11 changes: 6 additions & 5 deletions tests/gmail/test_gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import pandas as pd
import pytest

googleapiclient = pytest.importorskip("googleapiclient")
from google.oauth2.credentials import Credentials
from unittest.mock import MagicMock, patch

google = pytest.importorskip("google")
googleapiclient = pytest.importorskip("googleapiclient")

from melusine.connectors.gmail import GmailConnector


Expand Down Expand Up @@ -43,7 +44,7 @@ def mocked_gc():
return_value,
)
mock_build.return_value = mock_service
mock_creds_from_file.return_value = Credentials("dummy")
mock_creds_from_file.return_value = google.oauth2.credentials.Credentials("dummy")

return GmailConnector(token_json_path="token.json", done_label="TRASH", target_column="target")

Expand Down Expand Up @@ -91,7 +92,7 @@ def test_init(mock_exists, mock_creds_from_file, mock_build, caplog):
return_value,
)
mock_build.return_value = mock_service
mock_creds_from_file.return_value = Credentials("dummy")
mock_creds_from_file.return_value = google.oauth2.credentials.Credentials("dummy")

# Creating an instance of GmailConnector
with caplog.at_level(logging.DEBUG):
Expand Down Expand Up @@ -134,7 +135,7 @@ def test_init_without_creds(mock_flow, mock_build, caplog):
return_value,
)
mock_build.return_value = mock_service
mock_flow.return_value.run_local_server.return_value = Credentials("dummy")
mock_flow.return_value.run_local_server.return_value = google.oauth2.credentials.Credentials("dummy")

# Creating an instance of GmailConnector
with caplog.at_level(logging.DEBUG):
Expand Down

0 comments on commit 4529ca1

Please sign in to comment.