Skip to content

Commit 2ffff39

Browse files
committed
fix: restore cleanup of SPARK_LOCAL_IP and PYARROW_IGNORE_TIMEZONE after import
PR #2123 removed the `finally` block that cleaned up environment variables set temporarily for importing `pyspark.pandas`. This causes SPARK_LOCAL_IP=127.0.0.1 to persist in os.environ, breaking non-YARN distributed Spark setups where executors need to connect to the actual driver IP instead of localhost. Restores the pre-v0.27.0 behavior: set env vars temporarily, import pyspark.pandas, then clean up. Fixes #2344
1 parent 53e3a50 commit 2ffff39

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

pandera/external_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
def _set_pyspark_environment_variables():
77
"""Sets environment variables for pyspark."""
88

9+
is_spark_local_ip_dirty = False
10+
is_pyarrow_ignore_timezone_dirty = False
11+
912
try:
1013
# try importing pyspark to see if it exists. This is important because the
1114
# pandera.typing module defines a Series type that inherits from
@@ -14,10 +17,17 @@ def _set_pyspark_environment_variables():
1417
# https://spark.apache.org/docs/3.2.0/api/python/user_guide/pandas_on_spark/typehints.html#type-hinting-with-names
1518

1619
if os.getenv("SPARK_LOCAL_IP") is None:
20+
is_spark_local_ip_dirty = True
1721
os.environ["SPARK_LOCAL_IP"] = "127.0.0.1"
1822
if os.getenv("PYARROW_IGNORE_TIMEZONE") is None:
23+
is_pyarrow_ignore_timezone_dirty = True
1924
os.environ["PYARROW_IGNORE_TIMEZONE"] = "1"
2025

2126
import pyspark.pandas
2227
except (ImportError, ModuleNotFoundError):
2328
pass
29+
finally:
30+
if is_spark_local_ip_dirty:
31+
os.environ.pop("SPARK_LOCAL_IP")
32+
if is_pyarrow_ignore_timezone_dirty:
33+
os.environ.pop("PYARROW_IGNORE_TIMEZONE")

0 commit comments

Comments
 (0)