This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
[BUGFIX] Fix test_zero_sized_dim save/restore of np_shape state #20365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Tensor shapes can be interpreted in one of two modes, depending on whether "numpy shape semantics" have been enabled. There are unittests that test shape handling in both modes, but any one unittest should not make assumptions about the prevailing mode entering the test, nor should it permanently alter the mode for tests that follow (regardless of whether the test passes or fails). This PR fixes the test_operator.py::test_zero_sized_dim test, which was leaving numpy shape semantics set for follow-on tests. Running the test was found to cause failures in a following test_sparse_ndarray.py::def test_sparse_nd_pickle among other tests, as reported in issue #20337. This PR also fixes test_operator.py::test_boolean_mask and test_thread_local.py::test_np_global_shape, which do not properly save and restore the pre-test shape interpretation mode.
When running pytest with xdist and multiple workers, I'm not sure if the same set of tests are run on the same workers. If the assignment of tests to workers is non-deterministic, then failures of susceptible tests may be non-deterministic. In that case, this PR may also fix the non-deterministic issue #19915.
Regarding implementation, I chose not to use the more elegant np_shape() or use_np_shape() decorators in fixing these tests. Instead, I kept the use of set_np_shape() in order to retain some direct testing of this function from the unittests.
Checklist
Essentials
Changes