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
- ignore PD011 as too many false pos https://github.com/astral-sh/ruff/issues/6432 — committed to DanielYang59/pymatgen by DanielYang59 2 years ago
- Fix fixable `ruff` rules (#4015) * fix RUF017 * fix B018: useless expressions * NEED confirm: fix TRY004 type error * fix PGH003: bare # type: ignore * fix FBT003 boolean-positional-value... — committed to materialsproject/pymatgen by DanielYang59 2 years ago
- feat: use `seen_module` as elsewhere in codebase Suggestion: https://github.com/astral-sh/ruff/issues/6432#issuecomment-2986621950 — committed to jordyjwilliams/ruff by jordyjwilliams a year ago
Ruff is actually really trigger happy here, just posting another quick example that causes ruff to trigger while just messing around with python builtins:
@SerTetora I’m confused, it seems like it’s working as expected i.e., you should remove the
noqa: PD011because Ruff won’t highlighte.valuesforPD011. We updated the rules related to Pandas to only trigger when there’s apandasimport 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.