相关疑难解决方法(0)

如何禁用python警告

我正在处理代码,并使用warnings库抛出了很多(对我而言)无用的警告.阅读(/扫描)文档我只发现了一种禁用单个函数警告的方法.但我不想改变这么多的代码.

可能有旗帜python -no-warning foo.py吗?

你会推荐什么?

python suppress-warnings

350
推荐指数
11
解决办法
49万
查看次数

正则表达式错误 - 没有什么可重复的

我使用此表达式时收到错误消息:

re.sub(r"([^\s\w])(\s*\1)+","\\1","...")
Run Code Online (Sandbox Code Playgroud)

我在RegExr检查了正则表达式,它.按预期返回.但是当我在Python中尝试它时,我收到此错误消息:

raise error, v # invalid expression
sre_constants.error: nothing to repeat
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下吗?

python regex

59
推荐指数
5
解决办法
9万
查看次数

关于 read_file() 的 Geopandas 警告

我在使用 geopanda 的 read_file() 读取 geojson 时收到以下警告:

...geodataframe.py:422: RuntimeWarning: Sequential read of iterator was interrupted. Resetting iterator. This can negatively impact the performance.
  for feature in features_lst:
Run Code Online (Sandbox Code Playgroud)

这是我使用的代码示例:

crime_gdf = gpd.read_file('datasets/crimes.geojson', bbox=bbox)
Run Code Online (Sandbox Code Playgroud)

crimes.geojson 是一个包含大量点的文件,每个点都有一个“犯罪类型”

bbox 定义边界

代码按预期运行,但我不明白该警告。

编辑

我将 geojson 转换为feather,并收到相同的警告。

python geopandas

8
推荐指数
2
解决办法
1769
查看次数

抑制 python 警告

当我在 for 循环中迭代时,我不断收到相同的警告,我想抑制它。警告内容如下:

C:\Users\Nick Alexander\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\preprocessing\data.py:193: UserWarning: Numerical issues were encountered when scaling the data and might not be solved. The standard deviation of the data is probably very close to 0. warnings.warn("Numerical issues were encountered "

产生警告的代码如下:

def monthly_standardize(cols, df_train, df_train_grouped, df_val, df_val_grouped, df_test, df_test_grouped):
    # Disable the SettingWithCopyWarning warning
    pd.options.mode.chained_assignment = None
    for c in cols:
        df_train[c] = df_train_grouped[c].transform(lambda x: scale(x.astype(float)))
        df_val[c] = df_val_grouped[c].transform(lambda x: scale(x.astype(float)))
        df_test[c] = df_test_grouped[c].transform(lambda x: scale(x.astype(float)))
    return df_train, df_val, df_test
Run Code Online (Sandbox Code Playgroud)

我已经禁用了一个警告。我不想禁用所有警告,我只想禁用此警告。我正在使用 python 3.7 和 …

python suppress-warnings

5
推荐指数
2
解决办法
2万
查看次数

在 GCP 脚本中使用最终用户凭据时禁用警告

我正在使用Python 客户端库运行一些脚本来在 GCP 中执行一些临时作业。
这些是临时的,因此我相信它们应该在我的最终用户凭据而不是服务帐户上运行。

我不断看到此警告,这使得调试我的脚本标准输出变得困难:

UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK without a quota project. You might receive a "quota exceeded" or "API not enabled" error. We recommend you rerun `gcloud auth application-default login` and make sure a quota project is added. Or you can use service accounts instead. For more information about service accounts, see https://cloud.google.com/docs/authentication/
Run Code Online (Sandbox Code Playgroud)

我执行了建议的操作gcloud auth application-default login,但仍然重复出现相同的警告消息。

如何禁用此警告?

google-cloud-platform

1
推荐指数
1
解决办法
5476
查看次数