Hi,
I’m using SonarCloud for Python via AzureDevOps pipelines and I get a lot of false positive ‘unused local variable’ hits for referencing variables using the ‘@’ notation in a Pandas dataframe query.
src: pandas.DataFrame.query — pandas 2.1.3 documentation
You can refer to variables in the environment by prefixing them with an ‘@’ character like@a + b
.
Considering the above is a valid Python, referencing variables with the ‘@’ character in query strings should not cause an ‘unused local variable’ code smell. It is very annoying to have to mark tens of code smells as false positives every single time.
Some sample code that should reproduce the issue:
import pandas as pd
d = {'area': ['fictional_town', 'fictional_city'], 'population': [100, 2000]}
sample_df = pd.DataFrame(data=d)
area_of_interest = 'fictional_city'
pop = sample_df.query('area == @area_of_interest').population
Hopefully this can be resolved somehow or is there a work around to prevent this from being flagged?