Skip to content

TST Refactor common tests for set_output #27258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

thomasjpfan
Copy link
Member

Reference Issues/PRs

Related to #25896

What does this implement/fix? Explain your changes.

This PR

  • Refactors the set_output common tests to be more generic so it is easier to extend and support polars DataFrames.
  • Combines the local and global set_output common tests so they can share code.

@github-actions
Copy link

github-actions bot commented Aug 31, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: e018a19. Link to the linter CI: here

Copy link
Member

@lorentzenchr lorentzenchr left a comment

Choose a reason for hiding this comment

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

LGTM
Just some questions.

if "2darray" not in tags["X_types"] or tags["no_validation"]:
return
except ImportError: # pragma: no cover
raise SkipTest("pandas is not installed: not checking set output")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise SkipTest("pandas is not installed: not checking set output")
raise SkipTest("pandas is not installed: not checking set_output")

def check_global_output_transform_pandas(name, transformer_orig):
"""Check that setting globally the output of a transformer to pandas lead to the
right results."""
def _check_set_output_transform_pandas_context(name, transformer_orig, context):
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this function any more? It just calls _check_set_output_transform_dataframe.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like to have it because it configures callable such as is_supported_dataframe, etc. for the dataframe library:

    _check_set_output_transform_dataframe(
        name,
        transformer_orig,
        "pandas",
        is_supported_dataframe=lambda X: isinstance(X, pd.DataFrame),
        create_dataframe=lambda X, columns, index: pd.DataFrame(
            X, columns=columns, copy=False, index=index
        ),
        assert_frame_equal=pd.testing.assert_frame_equal,
        context=context,
    )

The alternative is to repeat the code in check_set_output_transform_pandas and check_global_output_transform_pandas

Comment on lines +4653 to +4654
def check_set_output_transform_pandas(name, transformer_orig):
_check_set_output_transform_pandas_context(name, transformer_orig, "local")
Copy link
Member

Choose a reason for hiding this comment

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

Same here, do we need it?
Answer can be yes as used in several places.

Copy link
Member

@lorentzenchr lorentzenchr left a comment

Choose a reason for hiding this comment

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

Typo

Co-authored-by: Christian Lorentzen <lorentzen.ch@gmail.com>
@glemaitre
Copy link
Member

We can close this PR @thomasjpfan?

@thomasjpfan
Copy link
Member Author

Yes, lets close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants