ruff: PD rules trigger on non-Pandas DataFrames

command: ruff check test.py ruff version: ruff 0.0.282 settings: select = ['ALL']

example:

import polars as pl

pldf = pl.DataFrame()
pldf.pivot()  # PD010 `.pivot_table` is preferred to `.pivot` or `.unstack`; provides same functionality

polars DataFrame provides .pivot() function but no .pivot_table() unlike pandas.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 7
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Ruff is actually really trigger happy here, just posting another quick example that causes ruff to trigger while just messing around with python builtins:

# ruff: noqa: F841
# pyright: reportUnusedVariable=false

x = {}
values_dict_func = x.values  # PD011

@SerTetora I’m confused, it seems like it’s working as expected i.e., you should remove the noqa: PD011 because Ruff won’t highlight e.values for PD011. We updated the rules related to Pandas to only trigger when there’s a pandas import in the module (https://github.com/astral-sh/ruff/pull/14671).

Currently the pandas rules are applied on many non pandas objects. For example PD011 tries to stop you from using .values anywhere, even if you use a library where you should use it. Therefore some kind of check, if the object is even belonging to pandas would be pretty useful.