2016-05-20 5 views
5

私は最近、私のマシンのいずれかにPythonのnumpyのパッケージを更新し、そしてどうやら私は今しばらくa deprecated feature of numpyに頼ってきた:上記のリンクでのコメンターのNumpyのDeprecationWarningが表示されないのはなぜですか?

>>> np.__version__ 
'1.10.4' 
>>> a = np.ones(10, dtype=np.uint16) 
>>> a /= 0.5 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: ufunc 'true_divide' output (typecode 'd') could not be coerced to provided output parameter (typecode 'H') according to the casting rule ''same_kind'' 

一つが指摘:

は、おそらくあなたは永遠に ため、非推奨の警告を見ていないこと。)

を...正しいである、私はしませんでした。

しかし、なぜ?非推奨の警告を見逃してしまったのはどうでしたか?

>>> np.__version__ 
'1.9.2' 
>>> a = np.ones(10, dtype=np.uint16) 
>>> a /= 0.5 
>>> a 
array([2, 2, 2, 2, 2, 2, 2, 2, 2, 2], dtype=uint16) 

を...しかしは、この警告をトリガしないでください。

the documentationと一致

、この同じコードは、私の以前のnumpyのバージョンでは異なる働いていましたか?私はnumpyが廃止警告をどのように処理するのか誤解していますか? 他の廃止予定の警告が表示されないようにするにはどうすればよいですか

私のPython環境:

Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] on win32 
+1

それらはデフォルトで無視されている – wim

答えて

6

がDeprecationWarningがignored by defaultあります。あなたは-Wd flagでのPythonを実行することにより、いずれか、それらを有効にする必要があります。

python -Wd my_source_file.py 

またはDeprecationWarningを無視するものを上書きします新しい警告フィルタの仕様をインストールすることによって:

import warnings 

# Print any warning the first time a given source line issues them, 
# overriding built-in filters that ignore some warning types. 
warnings.filterwarnings("default") 
+0

イエス、知っておいてよかった。私の教育の大きな穴、それを修正していただきありがとうございます。 – Andrew

+1

こんにちは、ありがとう。野生。 btw私はあなたが 'warnings.filterwarnings'(複数形)ではなく' warnings.filterwarning'を意味すると思います。 –

+0

@MaxPower:おっと!一定。 – user2357112

関連する問題