[
https://issues.apache.org/jira/browse/SPARK-58071?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated SPARK-58071:
-----------------------------------
Labels: pull-request-available (was: )
> 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: PySpark, Structured Streaming
> Affects Versions: 4.2.0, 5.0.0
> Reporter: Hyukjin Kwon
> Priority: Major
> Labels: pull-request-available
>
> 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]