MAINT - changing TableVectorizer tests so that they use df_module #1618
Conversation
|
Addressing #1441 |
df_module
|
|
||
| def test_get_preprocessors(): | ||
| X = _get_clean_dataframe() | ||
| def test_get_preprocessors(df_module): |
There was a problem hiding this comment.
For the moment I am changing the dataframe inside the test but later I will update the _get_clean_dataframe function
|
This PR was complicated by the fact that some of the tests are checking for pandas-specific behaviors and conditions. Some tests must be skipped with min-optional-reqs because polars support was added in scikit-learn 1.4, so in some specific cases tests could not pass when run using polars. The main changes revolved around modifying the functions Some other changes had to be made to get around how polars and pandas have different indexing and dtype representations. At this point, most of the tests (those that are not being skipped, at least) fully support both pandas and polars. However, there are some tests that may need some refinement. Given that this isn't a user-facing issue, and in the interest of avoiding conflicts, I think we should merge this and leave further improvements to future PRs. |
|
|
||
| @pytest.mark.parametrize("X, dict_expected_types", X_tuples) | ||
| def test_auto_cast(X, dict_expected_types): | ||
| def test_auto_cast(X_tuples_fixture): |
There was a problem hiding this comment.
I would have found it markedly more readable to use "@pytest.mark.parametrize" (https://docs.pytest.org/en/stable/how-to/parametrize.html#parametrize-basics) instead of the fixture.
Is there a reason that you did not consider this option?
There was a problem hiding this comment.
I don't think parametrize plays well with the fact we need to pass df_module to the functions
GaelVaroquaux
left a comment
There was a problem hiding this comment.
I had a comment about the fixture, which I find less readable than a parametrize.
However, I realize that we are already using super massively fixtures in skrub test, so it's consistent with our fixture usage. Hence, I'm happy to take push back on my comment.
| _get_dirty_dataframe(df_module, categorical_dtype="category"), | ||
| _get_mixed_types_dataframe(df_module), | ||
| _get_mixed_types_array(), | ||
| ] |
There was a problem hiding this comment.
Same thing, I would much rather prefer a "@pytest.mark.parametrize", which is more explicit, than the fixture
There was a problem hiding this comment.
Is this what you'd expect with parametrize? I find this far less readable than the fixture to be honest.
@pytest.mark.parametrize(
"X",
[
pytest.param(_get_clean_dataframe, id="clean_dataframe"),
pytest.param(lambda df_module: _get_dirty_dataframe(df_module, categorical_dtype="object"), id="dirty_dataframe_object"),
pytest.param(lambda df_module: _get_dirty_dataframe(df_module, categorical_dtype="category"), id="dirty_dataframe_category"),
pytest.param(_get_mixed_types_dataframe, id="mixed_types_dataframe"),
pytest.param(lambda _: _get_mixed_types_array(), id="mixed_types_array"),
],
)Unless there is a way of accessing df_module without the lambda functions, I think that having parametrize makes harder to understand
There was a problem hiding this comment.
Yes, this is what I was expecting.
I find this more readable because it introduce less conceptual things to understand and more locality in the code: the values are defined explicitly close where they are used. The fixture defines things very implicitly and far.
rcap107
left a comment
There was a problem hiding this comment.
I had a comment about the fixture, which I find less readable than a parametrize.
However, I realize that we are already using super massively fixtures in skrub test, so it's consistent with our fixture usage. Hence, I'm happy to take push back on my comment.
Part of why we used fixtures was because they're already very heavily used in the tests, however I think they're also more readable in this situation, where we need to pass df_module to the functions in order to generate the different variants of the datasets.
GaelVaroquaux
left a comment
There was a problem hiding this comment.
LGTM
Thanks a lot @gabrielapgomezji and @rcap107 !!
…krub-data#1618) Co-authored-by: GOMEZ JIMENEZ Gabriela <gabriela.gomez-jimenez@inria.fr> Co-authored-by: Gabriela <gabs@Riccardos-MacBook-Air.local> Co-authored-by: Riccardo Cappuzzo <riccardo.cappuzzo@gmail.com>
Modifying tests from table vectorizer to add df_module.
Changed a part, but there are others that might need a bit more change as test_handle_unknown_category