BUG fix deprecation of `limit` and `fill_method` in `pct_change`
State: closed

- [ ] Towards #53491
- [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests)
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit)
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file

I'm thinking that we should not over-complicate things by allowing `obj.pct_change()`. The thing is, even if users do `obj.ffill/bfill().pct_change()`, a warning will still be raised unless we check for NA values, for instance, #54981. I propose that we should let users use `obj.ffill/bfill().pct_change(fill_method=None)` to suppress the warnings, and this PR intends to give extra specific deprecation warning messages.

I haven't added test cases for it, but want to make sure if this is the right way to go. Ping @rhshadrach and @jbrockmendel who were involved in the discussion in the original issue. I'm seeing many users and libraries complaining about this might be better to get this done before the next release.


Labels:
name: Bug
name: Algos
description: Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff

Comments:
@rhshadrach I've implemented your suggestions, please check if it is correct. I've also updated the test cases and now they seem to pass correctly. Not sure if I need to add some additional tests?

By the way, for instance
```python
>>> ser = pd.Series([np.nan, 1, 2, 3, np.nan])
>>> ser.bfill().pct_change()
```
still raises a warning. Should we fix that?
/preview
Website preview of this PR available at: https://pandas.pydata.org/preview/55527/
Also - this needs a whatsnew note.
Done, not sure if the changelog should be added in `v2.2.0` or in `v2.1.2`. Currently it is in `v2.2.0` but let me know if this is wrong or the wording needs to be corrected.

Also, may I have your response to https://github.com/pandas-dev/pandas/pull/55527#issuecomment-1763606520 please @rhshadrach?
From https://github.com/pandas-dev/pandas/pull/55527#issuecomment-1763606520:

> still raises a warning. Should we fix that?

I believe the behavior is going to change between now and pandas 3.0. So that means we need to warn.
Done @rhshadrach, thanks for your review!
Bumping off the milestone.
Thanks @Charlie-XIAO 
Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

1. Checkout backport branch and update it.

```
git checkout 2.1.x
git pull
```

2. Cherry pick the first parent branch of the this PR on top of the older branch:
```
git cherry-pick -x -m1 54814c3bc022b91447c27e72b8f79cdac1f6df15
```

3. You will likely have some merge/cherry-pick conflict here, fix them and commit:

```
git commit -am 'Backport PR #55527: BUG fix deprecation of `limit` and `fill_method` in `pct_change`'
```

4. Push to a named branch:

```
git push YOURFORK 2.1.x:auto-backport-of-pr-55527-on-2.1.x
```

5. Create a PR against branch 2.1.x, I would have named this PR:

> "Backport PR #55527 on branch 2.1.x (BUG fix deprecation of `limit` and `fill_method` in `pct_change`)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the `Still Needs Manual Backport` label once the PR gets merged.

If these instructions are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).
                
@meeseeksdev backport 2.1.x
Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

1. Checkout backport branch and update it.

```
git checkout 2.1.x
git pull
```

2. Cherry pick the first parent branch of the this PR on top of the older branch:
```
git cherry-pick -x -m1 54814c3bc022b91447c27e72b8f79cdac1f6df15
```

3. You will likely have some merge/cherry-pick conflict here, fix them and commit:

```
git commit -am 'Backport PR #55527: BUG fix deprecation of `limit` and `fill_method` in `pct_change`'
```

4. Push to a named branch:

```
git push YOURFORK 2.1.x:auto-backport-of-pr-55527-on-2.1.x
```

5. Create a PR against branch 2.1.x, I would have named this PR:

> "Backport PR #55527 on branch 2.1.x (BUG fix deprecation of `limit` and `fill_method` in `pct_change`)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the `Still Needs Manual Backport` label once the PR gets merged.

If these instructions are inaccurate, feel free to [suggest an improvement](https://github.com/MeeseeksBox/MeeseeksDev).