Hyukjin Kwon created SPARK-58071:
------------------------------------

             Summary: Do not import numpy at 'import pyspark' time in 
stateful_processor_api_client
                 Key: SPARK-58071
                 URL: https://issues.apache.org/jira/browse/SPARK-58071
             Project: Spark
          Issue Type: Bug
          Components: Structured Streaming, PySpark
    Affects Versions: 4.2.0, 5.0.0
            Reporter: Hyukjin Kwon


SPARK-57760 moved `import numpy as np` to the module top level (inside a 
try/except ImportError) in 
`python/pyspark/sql/streaming/stateful_processor_api_client.py`. This module is 
transitively imported by `import pyspark` (pyspark -> pyspark.sql -> 
pyspark.sql.streaming -> stateful_processor_api_client), so numpy is now 
imported during `import pyspark`.

This breaks the fast-import guarantee enforced by 
`python/pyspark/tests/test_import_spark.py::ImportSparkTest::test_import_spark_libraries`,
 which fails with:

{code}
AssertionError: Unexpected 3rd party package 'numpy' imported during 'import 
pyspark'
{code}

The scheduled Non-ANSI builds on master and branch-4.x have been failing 
because of this (e.g. build_non_ansi.yml).

Before SPARK-57760, numpy was imported lazily inside `_serialize_to_bytes`. The 
fix is to keep numpy out of the module top level: resolve it lazily via a 
cached `has_numpy()` helper and import numpy inside `_normalize_state_value` 
only when normalizing values. Behavior is unchanged.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to