1

This question is a followup from here: How to disable Python warnings? I have the following code:

from prettytable import PrettyTable 
import operator
import calendar
import warnings
with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    warnings.filterwarnings("ignore", category=FutureWarning)
    import pandas as pd, datetime, calendar
...
{rest of my code}

I am trying to suppress these warning:

<ipython-input-3-7e458c7b53b6>:22: FutureWarning: weekofyear and week have been deprecated, please use DatetimeIndex.isocalendar().week instead, which returns a Series.  To exactly reproduce the behavior of week and weekofyear and return an Index, you may call pd.Int64Index(idx.isocalendar().week)
  data['week'] = data.index.week

For some reason this is not ignoring these warnings. I am trying to ignore the warning of just in pandas where they are originating from and not the warning which i may get from other packages. Could you please advise as to why this is not working?

JaneDoe
  • 171
  • 2
  • 10

2 Answers2

0

From my little research, pandas seems to have some tricky way of doing it. have you tried import warnings; warnings.filterwarnings("ignore")?

You can also check this thread. And if the warning persists just let it be, it won't stop your code from running.

Godwin Mathias
  • 326
  • 4
  • 12
  • Thanks for your answer but that would ignore all the warning, not just the warning for pandas since you have not mentioned any packages. I want the warning to just be suppressed for certain packages not others :) – JaneDoe Jun 02 '21 at 02:28
  • It alright, have you checked the thread yet? It really said a lot about this issue. – Godwin Mathias Jun 02 '21 at 03:06
  • Neither this nor the thread silenced the warning for me. @JaneDoe I see you have accepted the answer, so how did you exactly solve the problem? – gsamaras Jun 08 '22 at 07:34
0

To only suppress FutureWarning messages:

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
Peter Hanley
  • 1,254
  • 1
  • 11
  • 19