-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Improve tests to make them run on variously typed data using the global_dtype
fixture
#22881
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
Comments
I have tried to expand the description of this issue, but github fails to take my update into account for some reason. Here is a copy of the edited issue description: https://gist.github.com/ogrisel/d6867ca3c8c64e0b3d789f5a2f9ce067 |
Thanks, I just pasted your snippet in the description to replace the text. |
Regarding dtype preservation for fitted attributes, wouldn't it be better to introduce global checks for it with tags? I feel that we might spend a lot of time duplicating checks in many tests, potentially inserting a lot of To me it seems that this would better be addressed by another meta-issue similar to #11000. What do you think? cc @glemaitre |
I changed it to hard because it requires some knowledge to figure out which test should use the fixture and which test should not. |
I think the list should be updated to remove all estimators that do not preserve the dype yet. |
@jjerphan just tried this for
|
I extended the tests of #22806 using a combination of |
@adam2392: some estimators aren't preserving the provided input dtype. In that case, it still makes sense to extend the tests adding TODO, as explained in the description of this issue:
|
Context: the new
global_dtype
fixture andSKLEARN_RUN_FLOAT32_TESTS
environment variableIntroduction of low-level computational routines for 32bit motivated an extension of tests to run them on 32bit.
In this regards, #22690 introduced a new
global_dtype
fixture as well has theSKLEARN_RUN_FLOAT32_TESTS
env. variable to make it possible to run the test on 32bit data.Running test on 32bit can be done using
SKLEARN_RUN_FLOAT32_TESTS=1
.For instance, this run the first
global_dtype
-parametrised test:This allows running tests on 32bit dataset on some CI job, and currently a single CI job is used to run tests on 32bit.
More details about the fixture in the online dev doc for the
SKLEARN_TESTS_GLOBAL_RANDOM_SEED
env variable:https://scikit-learn.org/dev/computing/parallelism.html#environment-variables
Guidelines to convert existing tests
Not all scikit-learn tests must use this fixture. We must parametrise tests that actually assert closeness of results using
assert_allclose
. For instance, tests that check for the exception messages raised when passing invalid inputs must not be converted.Tests using
np.testing.assert_allclose
must now usesklearn.utils._testing.assert_allclose
as a drop-in replacement.Check that the dtype of fitted attributes or return values that depend on the dtype of the input datastructure actually have the expected dtype: typically when all inputs are continuous values in float32, it is often (but not always) the case that scikit-learn should carry all arithmetic operations at that precision level and return output arrays with the same precision level. There can be exceptions, in which case they could be made explicit with an inline comment in the test, possibly with a
TODO
marker when one thing that the current behavior should change (see the related: Preserving dtype for float32 / float64 in transformers #11000 and Estimator check for dtype preservation for regressors #22682 for instance).To avoid having to review huge PRs that impact many files at once and can lead to conflicts, let's open PRs that edit at most one test file at a time. For instance use a title such as:
Please reference Improve tests to make them run on variously typed data using the
global_dtype
fixture #22881 (i.e. this issue) in the description of the PR and put the full filename of the test file you edit in the title of the PR.To convert an existing test with a fixed dtype, the general pattern is to rewrite a function such as:
to:
and then check that the test is passing on 32bit datasets
Failures are to be handle on a case-by-case basis.
List of test modules to upgrade
LocalOutlierFactor
#22665SpectralClustering
#22669LocalOutlierFactor
#22665Note that some of those files might not have any test to update.
The text was updated successfully, but these errors were encountered: