BUG: Fix Series.str.contains with compiled regex on Arrow string dtype
State: closed

closes #61942 

This PR fixes an issue in `Series.str.contains()` where passing a compiled regex object failed when the underlying string data is backed by PyArrow.

Please, provide feedback if my approach is not correct , I would love to improve and contribute in this. 


Labels:
name: Bug
name: Strings
description: String extension data type and string data
name: Still Needs Manual Backport
name: Arrow
description: pyarrow functionality

Comments:
Hi @mroeschke 
I've worked on the issue
BUG: Fix Series.str.contains with compiled regex on Arrow string dtype ([#61942])
and have opened a pull request for it.

I'd appreciate it if you could take a look and share your feedback.
Please let me know if anything needs to be improved or clarified.

Thanks!
Thankyou for the feedback!
I will update that.
Additionally, if this is something that is not implemented by pyarrow, we should not raise a NotImplementedError, but fall back on the python object implementation (you can see a similar pattern in some other str methods, like `ArrowStringArray._str_replace`)
@jorisvandenbossche Thank you for the feedback! I will update the PR accordingly.

Would you mind letting me know the reason behind the one failing check (pre-commit.ci)?
Thanks again!
> Would you mind letting me know the reason behind the one failing check (pre-commit.ci)?

ruff is failing, which is used for auto formatting. I would recommend to install the pre-commit locally to avoid having this fail on CI: https://pandas.pydata.org/docs/dev/development/contributing_codebase.html#pre-commit
hi @jorisvandenbossche
Please review this PR, and if area needs changes please suggest.
Also I want to know if i would need to write unit test for this .

Thankyou!
Can you try to run the test you added locally? Then you can make sure to get it working correctly. Right now it is still failing according to CI
Sure, I will try to run tests locally and update this PR .
Thankyou !
Thanks @Aniketsy
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.3.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 1d2233185083423b8ecb27986f11175b2d6e8fa6
```

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

```
git commit -am 'Backport PR #61946: BUG: Fix Series.str.contains with compiled regex on Arrow string dtype'
```

4. Push to a named branch:

```
git push YOURFORK 2.3.x:auto-backport-of-pr-61946-on-2.3.x
```

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

> "Backport PR #61946 on branch 2.3.x (BUG: Fix Series.str.contains with compiled regex on Arrow string dtype)"

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).
                
@jorisvandenbossche 
Big thanks for patiently guiding me at every step and helping me get this right. I learned a lot from this, and I’m glad the PR is now merged!
Thankyou .
@Aniketsy you're welcome!
Manual backport -> https://github.com/pandas-dev/pandas/pull/62116