PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 28, 2022

[FIXED] why I cannot suppress warning with regex using warnings.filterwarnings

 April 28, 2022     pandas, python, regex, warnings     No comments   

Issue

I want to suppress a specific type of warning using regular expression. The warning message is:

C:\Anaconda3\lib\site-packages\pandas\core\indexing.py:420: SettingWithCopyWarning:

A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy 
self.obj[item] = s

My way of suppressing filter:

import warnings
warnings.filterwarnings("ignore", message= ".*A value is trying to.*")

However, it failed. I did try pasting different part of the warning message into the regex but still failed. I want to know why.


Solution

Your regular expression does not match the correct message string.

r".*A Value is trying to.*" does not match "\nA value is trying to be.*" because r"." matches everything except the newline character.

Sometimes it can be tricky to figure out what the actual message string is without looking at the source code of the module that generated the warning.



Answered By - Daniel Ching
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing