Programing

Pandas Future 경고를 억제하는 방법은 무엇입니까?

lottogame 2020. 9. 15. 19:10
반응형

Pandas Future 경고를 억제하는 방법은 무엇입니까?


프로그램을 실행하면 판다 스는 매번 아래와 같은 '미래 경고'를 해요.

D:\Python\lib\site-packages\pandas\core\frame.py:3581: FutureWarning: rename with inplace=True  will return None from pandas 0.11 onward
  " from pandas 0.11 onward", FutureWarning) 

나는 메시지를 받았지만 Pandas가 그러한 메시지를 계속해서 보여주는 것을 멈추고 싶습니다 .Pandas가 'Future warning'을 표시하지 않도록 설정할 수있는 기본 매개 변수가 있습니까?


github 에서 이것을 찾았습니다 ...

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)

@bdiamante의 답변은 부분적으로 만 도움이 될 수 있습니다. 경고를 표시하지 않은 후에도 메시지가 계속 표시되는 경우 pandas라이브러리 자체가 메시지를 인쇄하고 있기 때문 입니다. Pandas 소스 코드를 직접 수정하지 않으면 할 수있는 일이별로 없습니다. 내부적으로 억제 할 수있는 옵션이나 재정의하는 방법이있을 수 있지만 찾을 수 없습니다.


사람들을 위해 해야 할 이유를 알고 ...

깨끗한 작업 환경을 원한다고 가정 해보십시오. 스크립트 맨 위에 pd.reset_option('all'). Pandas 0.23.4를 사용하면 다음을 얻을 수 있습니다.

>>> import pandas as pd
>>> pd.reset_option('all')
html.border has been deprecated, use display.html.border instead
(currently both are identical)

C:\projects\stackoverflow\venv\lib\site-packages\pandas\core\config.py:619: FutureWarning: html.bord
er has been deprecated, use display.html.border instead
(currently both are identical)

  warnings.warn(d.msg, FutureWarning)

: boolean
    use_inf_as_null had been deprecated and will be removed in a future
    version. Use `use_inf_as_na` instead.

C:\projects\stackoverflow\venv\lib\site-packages\pandas\core\config.py:619: FutureWarning:
: boolean
    use_inf_as_null had been deprecated and will be removed in a future
    version. Use `use_inf_as_na` instead.

  warnings.warn(d.msg, FutureWarning)

>>>

@bdiamante의 조언에 따라 warnings라이브러리 를 사용합니다 . 이제 말 그대로 경고 가 제거되었습니다. 그러나 몇 가지 성가신 메시지가 남아 있습니다.

>>> import warnings
>>> warnings.simplefilter(action='ignore', category=FutureWarning)
>>> import pandas as pd
>>> pd.reset_option('all')
html.border has been deprecated, use display.html.border instead
(currently both are identical)


: boolean
    use_inf_as_null had been deprecated and will be removed in a future
    version. Use `use_inf_as_na` instead.

>>>

실제로 모든 경고를 비활성화 하면 동일한 출력이 생성됩니다.

>>> import warnings
>>> warnings.simplefilter(action='ignore', category=Warning)
>>> import pandas as pd
>>> pd.reset_option('all')
html.border has been deprecated, use display.html.border instead
(currently both are identical)


: boolean
    use_inf_as_null had been deprecated and will be removed in a future
    version. Use `use_inf_as_na` instead.

>>>

표준 라이브러리 의미에서 이것은 진정한 경고가 아닙니다 . Pandas는 자체 경고 시스템을 구현합니다. grep -rn경고 메시지에서 실행 하면 pandas경고 시스템이 다음에서 구현 되었음을 보여줍니다 core/config_init.py.

$ grep -rn "html.border has been deprecated"
core/config_init.py:207:html.border has been deprecated, use display.html.border instead

Further chasing shows that I don't have time for this. And you probably don't either. Hopefully this saves you from falling down the rabbit hole or perhaps inspires someone to figure out how to truly suppress these messages!


Warnings are annoying. As mentioned in other answers, you can suppress them using:

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)

But if you want to handle them one by one and you are managing a bigger codebase, it will be difficult to find the line of code which is causing the warning. Since warnings unlike errors don't come with code traceback. In order to trace warnings like errors, you can write this at the top of the code:

import warnings
warnings.filterwarnings("error")

But if the codebase is bigger and it is importing bunch of other libraries/packages, then all sort of warnings will start to be raised as errors. In order to raise only certain type of warnings (in your case, its FutureWarning) as error, you can write:

import warnings
warnings.simplefilter(action='error', category=FutureWarning)

참고URL : https://stackoverflow.com/questions/15777951/how-to-suppress-pandas-future-warning

반응형