Skip to content

Fix annotations of str methods that accept regular expressions #1278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025

Conversation

hamdanal
Copy link
Contributor

  • Closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added: Please use assert_type() to assert the type of any return value

These methods accept compiled regular expressions as documented in pandas and tested at runtime.

@twoertwein
Copy link
Member

Thank you for your well-tested PR!

These methods accept compiled regular expressions as documented in pandas

It is not clear to me if the documentation suggests that re.Pattern objects are officially accepted (for example here https://pandas.pydata.org/docs/reference/api/pandas.Series.str.extractall.html). The type is often explicitly annotated as str in pandas and the fact that not all functions accept it might hint that it is not officially accepted. I will defer to @Dr-Irv.

Feel free to open an issue/PR at pandas about it.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jul 24, 2025

It is not clear to me if the documentation suggests that re.Pattern objects are officially accepted (for example here https://pandas.pydata.org/docs/reference/api/pandas.Series.str.extractall.html). The type is often explicitly annotated as str in pandas and the fact that not all functions accept it might hint that it is not officially accepted. I will defer to @Dr-Irv.

I think the PR discussion in pandas-dev/pandas#61879 will lead to the docs getting corrected. So I'll accept this PR as is.

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @hamdanal

@Dr-Irv Dr-Irv merged commit f141c69 into pandas-dev:main Jul 24, 2025
13 checks passed
@hamdanal hamdanal deleted the str-patterns branch July 26, 2025 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants