This rule raises an issue when the pandas.DataFrame.values is used instead of the pandas.DataFrame.to_numpy() method.

Why is this an issue?

The values attribute and the to_numpy() method in pandas both provide a way to return a NumPy representation of the DataFrame. However, there are some reasons why the to_numpy() method is recommended over the values attribute:

How to fix it

Use the to_numpy() method instead of the values attribute to get a NumPy representation of the DataFrame.

Code examples

Noncompliant code example

import pandas as pd

df = pd.DataFrame({
        'X': ['A', 'B', 'A', 'C'],
        'Y': [10, 7, 12, 5]
    })

arr = df.values # Noncompliant: using the 'values' attribute is not recommended

Compliant solution

import pandas as pd

df = pd.DataFrame({
        'X': ['A', 'B', 'A', 'C'],
        'Y': [10, 7, 12, 5]
    })

arr = df.to_numpy() # Compliant

Resources

Documentation