为什么在python xarray中针对nan抛出“更大时遇到无效值"警告?难道难道通勤没有问题吗? [英] Why is 'invalid value encountered in greater' warning thrown in python xarray for nan? Shouldn't the nan commute without any issues?

查看:118
本文介绍了为什么在python xarray中针对nan抛出“更大时遇到无效值"警告?难道难道通勤没有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是一个哲学问题,旨在弄清楚为什么xarrays就是它的样子.

The following is philosophical question aimed at figuring out why xarrays is the way that it is.

我在弄清楚Xarrays进行以下操作时遇到了麻烦.

I'm having trouble figuring out the Xarrays way to do the following.

positive_values = values.where(values > 0)  

它遵循x-arrays语法,并使用xarrays计算我希望它执行的操作,但是会抛出此运行时警告.

It follows x-arrays syntax, and computes what I want it to do using xarrays, but throws this Runtime Warning.

RuntimeWarning: invalid value encountered in greater if not reflexive  

我的问题是,我如何滥用Xarrays ?

我想证明nans是出色的,因为它们在各个操作之间都是通勤的. (使发现或处理缺失的数据值变得容易)

I'd like to make the case that nans are excellent in the sense that they commute across across operations. (Making it easy to spot or deal with missing data values)

IE.

value = np.nan + 1  
final_value = value/2  
#final_value evaluates to 'nan'

这使得它们在X数组中的表示非常有用. xarrays可能缺少数据,但这不应停止跨数千个点的操作.

This make their representation in X-arrays very useful. xarrays may have missing data, but that shouldn't stop an operation across thousands of points.

为什么>不能在没有任何问题的情况下对nan进行通勤?如果这是我想要的行为,是否应该以其他方式执行此操作并忽略该错误?

Why doesn't > commute the nan without any issue? Should I be doing this some other way and ignore the error if this is the behavior that I want?

推荐答案

这不是故意的设计选择,应予以解决.

This was not an intentional design choice and should be fixed.

在与NaN进行比较时,NumPy会发出警告,因为结果可能令人惊讶,至少在您不熟悉与NaN进行比较的情况下:

NumPy issues warnings when doing comparisons with NaN, because the result may be surprising, at least if you are not familiar with how comparisons with NaN work:

In [6]: np.array([1, -1, np.nan]) > 0
/Users/shoyer/conda/envs/xarray-dev/bin/ipython:1: RuntimeWarning: invalid value encountered in greater
  #!/Users/shoyer/conda/envs/xarray-dev/bin/python
Out[6]: array([ True, False, False], dtype=bool)

可以说,如果结果类似于[True, False, NA],则会更直观,但是NumPy没有集成的缺失值支持.

Arguably, it would be more intuitive if the result was something like [True, False, NA], but NumPy doesn't have integrated missing value support.

直到最近(在熊猫0.19 ),熊猫会在所有操作中均忽略此类NumPy警告-无论该操作是否使用熊猫完成.由于xarray导入了熊猫,这意味着xarray操作也将这些错误忽略了.现在,我们需要添加自己的代码以使这些警告消失.

Until recently (in pandas 0.19), pandas silenced NumPy warnings of this type for all operations -- whether or not the operation was done with using pandas. Because xarray imports pandas, this meant these errors were silenced for xarray operations, too. Now, we'll need to add our own code to silence these warningss.

更新:自xarray v0.10起应解决此问题.如果仍然遇到问题,请在 http://github.com/pydata/xarray/上提交错误.问题

Update: This should be resolved as of xarray v0.10. If you are still encountering it, please file a bug at http://github.com/pydata/xarray/issues

这篇关于为什么在python xarray中针对nan抛出“更大时遇到无效值"警告?难道难道通勤没有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆