Skip to content

Commit

Permalink
✅ Refactored melusine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoPerrier committed Dec 12, 2023
1 parent 4c1378f commit de2f039
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
37 changes: 2 additions & 35 deletions tests/pipeline/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_pipeline_with_processors():
df = pd.DataFrame({"a": [dum0, dum0]})

# Fit the pipeline and transform the data
df_transformed = pipe.fit_transform(df)
df_transformed = pipe.transform(df)

# Most basic test, check that the pipeline returns a pandas DataFrame
assert isinstance(df_transformed, pd.DataFrame)
Expand All @@ -48,39 +48,6 @@ def test_pipeline_with_processors():
assert df_transformed["c"].iloc[0] == dum2


def test_pipeline_with_arbitrary_transformer():
class ArbitraryTransformer:
def __init__(self, dummy_attr=dum1):
self.dummy_attr = dummy_attr

def add_dummy_col(self, col_a_data):
return self.dummy_attr

def fit(self, x, y=None):
return self

def transform(self, x):
x["b"] = x["a"].apply(self.add_dummy_col)

return x

d1 = ArbitraryTransformer()

# Create pipeline
pipe = MelusinePipeline(steps=[("d1", d1)], verbose=True)

# Create data
df = pd.DataFrame({"a": [dum0, dum0]})

# Fit the pipeline and transform the data
df_transformed = pipe.fit_transform(df)

# Most basic test, check that the pipeline returns a pandas DataFrame
assert isinstance(df_transformed, pd.DataFrame)
assert "a" in df_transformed.columns
assert "b" in df_transformed.columns


def test_meta_pipeline():
d1 = DummyProcessor()
d2 = DummyProcessor(output_columns=("c",), dummy_attr=dum2)
Expand All @@ -95,7 +62,7 @@ def test_meta_pipeline():
df = pd.DataFrame({"a": [dum0, dum0]})

# Fit the pipeline and transform the data
df_transformed = meta_pipe.fit_transform(df)
df_transformed = meta_pipe.transform(df)

# Most basic test, check that the pipeline returns a pandas DataFrame
assert isinstance(df_transformed, pd.DataFrame)
Expand Down
6 changes: 3 additions & 3 deletions tests/pipeline/test_pipeline_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_pipeline_basic(dataframe_basic):
pipe = MelusinePipeline(steps=[("normalizer", normalizer), ("tokenizer", tokenizer)], verbose=True)

# Fit the pipeline and transform the data
df_transformed = pipe.fit_transform(df)
df_transformed = pipe.transform(df)

# Most basic test, check that the pipeline returns a pandas DataFrame
assert isinstance(df_transformed, pd.DataFrame)
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_pipeline_from_config(dataframe_basic):
pipe = MelusinePipeline.from_config(config_key=pipeline_key, verbose=True)

# Fit the pipeline and transform the data
df_transformed = pipe.fit_transform(df)
df_transformed = pipe.transform(df)

# Make basic tests
assert isinstance(df_transformed, pd.DataFrame)
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_pipeline_from_dict(dataframe_basic):
pipe = MelusinePipeline.from_config(config_dict=conf_pipeline_basic, verbose=True)

# Fit the pipeline and transform the data
df_transformed = pipe.fit_transform(df)
df_transformed = pipe.transform(df)

# Make basic tests
assert isinstance(df_transformed, pd.DataFrame)
Expand Down

0 comments on commit de2f039

Please sign in to comment.