HyukjinKwon commented on code in PR #59367:
URL: https://github.com/apache/spark/pull/59367#discussion_r4243971495


##########
python/pyspark/ml/torch/tests/test_data.py:
##########
@@ -0,0 +1,85 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import unittest
+
+import numpy as np
+
+from pyspark.ml.torch.data import _SparkPartitionTorchDataset

Review Comment:
   **Non-blocking (P2):** This module imports `pyspark.ml.torch.data` at import 
time, and that module does an unconditional `import torch` (`data.py:21`). 
torch is an optional dependency: it is only in the `ml_torch` group, not in 
`ci_classic_minimum`/`ci_connect_minimum`. So any interpreter without torch 
fails collecting this file with `ModuleNotFoundError: No module named 'torch'` 
instead of skipping it. Examples are the python-minimum image used by 
`build_python_minimum.yml` and the macOS hosted-runner job, which runs 
`pyspark-ml` without installing torch. The documented `python/run-tests 
--testnames pyspark.ml.torch.tests.test_data` command fails the same way. Once 
the module is registered for CI (see the other comment), those jobs would go 
red.
   
   A class-level `skipIf` on its own is not enough, because the module-level 
import fails first. Following the sibling `test_distributor.py`, something like 
this should work:
   
   ```python
   from pyspark.testing.utils import have_torch, torch_requirement_message
   
   if have_torch:
       from pyspark.ml.torch.data import _SparkPartitionTorchDataset
   
   
   @unittest.skipIf(not have_torch, torch_requirement_message)
   class TestGetFieldConverterVectorType(unittest.TestCase):
       ...
   ```
   
   Apply the same decorator to the other two test classes.
   
   **Verification:**
   - **Compatibility:** In an environment without torch, running the module 
produces skips rather than an import error.
   - **Behavior:** In an environment with torch, the dense, sparse, 
empty-sparse, unknown-type, scalar, array, and unsupported-type tests all 
execute and pass.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to