【问题标题】:Cannot supress PySpark warnings无法抑制 PySpark 警告
【发布时间】:2023-02-01 21:54:39
【问题描述】:

我在尝试抑制 pyspark 警告时遇到一些问题,特别是 spark API 上的 pandas。我目前拥有的:

import warnings
warnings.simplefilter(action='ignore', category=Warning)
warnings.filterwarnings("ignore")
import pandas as pd
from pyspark.sql import SparkSession
from pyspark.sql import functions as F
import pyspark.pandas as

%%capture
spark = SparkSession.builder\
    .master("local[32]")\
    .config("spark.driver.memory", "150g")
    .config("spark.driver.maxResultSize", "40g")\
    .config("spark.python.worker.memory", "1g")\
    .config("spark.num.executors","(3x-2)")\
    .config("spark.num.executor.cores","5")\
    .config("spark.driver.cores", "5")\
    .appName("Analysis")\
    .getOrCreate()
spark.sparkContext.setLogLevel("OFF")

接着是实际数据分析:

spark.catalog.clearCache()
enc = ps.read_parquet("/example_path/")
enc.columns = [i.lower() for i in enc.columns]
print(enc.en_end_date.min())
print(enc.en_end_date.max())
enc['year'] = enc.en_end_date.apply(lambda x: x.strftime('%Y') if pd.notnull(x) else np.nan)
enc['month'] = enc.en_end_date.apply(lambda x: x.strftime('%m') if pd.notnull(x) else np.nan)
enc['day'] = enc.en_end_date.apply(lambda x: x.strftime('%d') if pd.notnull(x) else np.nan)
enc[(enc.year >= 2024) & (enc.month >= 1) & (enc.day >= 1)]

这就是实际问题发生的地方。我完全被轰炸了:

/example/miniconda/lib/python3.8/site-packages/pyspark/python/lib/pyspark.zip/pyspark/pandas/internal.py:1573: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
/example/miniconda/lib/python3.8/site-packages/pyspark/python/lib/pyspark.zip/pyspark/pandas/internal.py:1573: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
/example/miniconda/lib/python3.8/site-packages/pyspark/python/lib/pyspark.zip/pyspark/pandas/internal.py:1573: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
/example/miniconda/lib/python3.8/site-packages/pyspark/python/lib/pyspark.zip/pyspark/pandas/internal.py:1573: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.

数百次。我只想关闭它。有什么建议么。

【问题讨论】:

  • 你设法解决了这个问题吗?我遇到了同样的问题
  • @ABaron 我不得不将我的 Pandas 版本回滚到 1.4.7。 (我认为)

标签: python pandas apache-spark pyspark suppress-warnings


【解决方案1】:

对于遇到此问题的任何人,请回滚您的 Pandas 版本,直到警告停止为止,不幸的是,没有其他方法可以抑制这种情况。

【讨论】:

    猜你喜欢
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多