Skip to content

Added FunctionTransformer test and wrap refenrece#443

Closed
nandevers wants to merge 4 commits intofeature-engine:mainfrom
nandevers:add-transformer-test
Closed

Added FunctionTransformer test and wrap refenrece#443
nandevers wants to merge 4 commits intofeature-engine:mainfrom
nandevers:add-transformer-test

Conversation

@nandevers
Copy link
Contributor

Issue: #416

This PR modifies:

feature_engine/feature_engine/wrappers/wrappers.py
feature_engine/tests/test_wrappers/test_sklearn_wrapper.py

Passed pytest tests/test_wrappers/test_sklearn_wrapper.py -k 'test_sklearn_transformer_wrapper' test successfully :

================================================================= warnings summary ==================================================================
<frozen importlib._bootstrap>:219
<frozen importlib._bootstrap>:219
<frozen importlib._bootstrap>:219
  <frozen importlib._bootstrap>:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 232 from PyObject

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================== 1 passed, 68 deselected, 3 warnings in 0.44s ====================================================

Copy link
Collaborator

@solegalli solegalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nandevers

Thank you so much for your contribution!! This is looking really good.

I've got a minor comment on the tests, could you have a look?

Also, the code style test is failing, this is probably because there are some blank lines where they shouldn't or some code lines longer than they should be.

Fortunately, this can be corrected automatically with a python library called black, and tested with a python library called flake8.

More info here:
https://feature-engine.readthedocs.io/en/latest/contribute/contribute_code.html#test-code-style

Would you want to try those out?

When you run black, make sure to do it in your file only and in the test file (not in the entire project). And when you commit, make sure you commit only those files.

I look forward to those changes :)

thanks a lot!

PS: let me know if you need anything.

assert output_feat == transformer.get_feature_names_out(varlist)


def test_sklearn_transformer_wrapper():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this test for something with more information about what the aim of the test is.

In this particular case, we are wrapping the FunctionTransformer and we want to ensure that this transformer can work with categorical variables. So maybe rename to test_function_transformer_works_with_categoricals.

We could also add a test to test that it work with numericals (I am getting greedy, sorry, but let me make a code suggestion for the new test):


    X = pd.DataFrame({
        "col1": [1, 2, 3],
        "col2": ["a", "b", "c"]
        })

    X_expected = pd.DataFrame({
        "col1": [2, 3, 4],
        "col2": ["a", "b", "c"]
        })

    transformer = SklearnTransformerWrapper(
        FunctionTransformer(lambda x: x+1,
        variables=["col1"]
    )

you get the gist ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there, I have included these changes and tested the functions. Everything seems ok now, would you please let me now if there's anything else I can do to make it better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@solegalli, it turns out I accidentally included this file in formatting changes as well... do you reckon we could keep it and merge it together with the others or should I remove it from this PR?
tests/test_selection/test_check_estimator_selectors.py

Thanks a bunch

@nandevers
Copy link
Contributor Author

@solegalli I am closing this PR because it is a little messy right now. I'll open a new one in a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants