astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
28.71k stars 930 forks source link

new rules for pandas 2.0 deprecations #8824

Open morotti opened 7 months ago

morotti commented 7 months ago

Hello,

First, thank you for making ruff, it's great!

There are rules around pandas to block deprecated pandas functions, mostly inspired from pandas-vet https://docs.astral.sh/ruff/rules/#pandas-vet-pd

pandas released a new major version 2.0 few months ago, with a bazillion of breaking changes. is it possible to add new rules to flag and automatically adjust deprecated imports?

import pandas.datetime is removed. to be replaced by import datetime.datetime.

import pandas.util.testing is removed. pandas.util.testing.assert_frame_equal -> pandas.testing.assert_frame_equal pandas.util.testing.assert_series_equal -> pandas.testing.assert_series_equal pandas.util.testing.assert_almost_equal -> numpy.assert_almost_equal there are other functions that were available but not all of them are available in a new location.

Thank you.

charliermarsh commented 7 months ago

Would definitely accept a contribution to this effect -- we've done the same for NumPy.

olsgaard commented 3 months ago

To what degree does ruff want to implement exceptions for different libraries?

For example, I find E712 Comparison to True should be cond is True problematic when sub-setting pandas data frames, e.g.

df[df['bool_column_with_nans']] #ValueError: Cannot mask with non-boolean array containing NA / NaN values

df[df['bool_column_with_nans'] == True] #Clear, readable, works, but a problem according to linter

As this issue is related to library specific rules, I am wondering to what degree these kind of things can be attached to the topic.