Skip to content

FIX-#7709: Return DataFrame from Series.str.extractall - #7722

Open
FullStraing wants to merge 6 commits into
modin-project:mainfrom
FullStraing:fix/str-extractall-return-dataframe-7709
Open

FullStraing wants to merge 6 commits into
modin-project:mainfrom
FullStraing:fix/str-extractall-return-dataframe-7709

Conversation

@FullStraing

Copy link
Copy Markdown

What do these changes do?

Fixes #7709.

Series.str.extractall wrapped the query compiler result in a Series, so for a single capture group it returned a Series of shape (3,) while pandas always returns a DataFrame (with a MultiIndex of the original index and the match number), of shape (3, 1) in the reported example. This PR makes StringMethods.extractall in modin/pandas/series_utils.py return a DataFrame instead, following the same local-import pattern as the sibling extract method.

test_str_extractall in modin/tests/pandas/test_series.py is extended to compare the result against pandas with eval_general for both a single-group pattern (r"([ab])") and a two-group pattern (r"([ab])(\d)"), inside the existing warns_that_defaulting_to_pandas_if(...) context, so the check that the operation defaults to pandas is kept.

Note: the tests were not run locally — this change was made in a browser-only environment, so CI will run them.

  • first commit message and PR title follow format outlined here

NOTE: If you edit the PR title to match this format, you need to add another commit (even if it's empty) or amend your last commit for the CI job that checks the PR title to pick up the new PR title.

@ptimizeroracle ptimizeroracle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ran this change on main 7ca200b (the hunk copied into a scratch patch of StringMethods.extractall, MODIN_ENGINE=python, pandas 2.3.3). against pandas on 84 cases (4 inputs, 3 index shapes, 7 patterns with named groups, an optional group, no match and re.I): main returns a Series in all 84, with the change all 84 match on type and df_equals. the new test fails on main and passes with the change.

two things:

  • black --check --diff modin/pandas/series_utils.py flags the hunk (blank line after the import, and return DataFrame(...) now fits on one line), so lint (black and isort) should go red once ci runs. main's file is clean with the same black (26.10.1).
  • ([ab])(\d) matches 0 rows of test_string_data, so that case compares two empty (0, 2) frames. ([a-zA-Z])(\d) gives 1 row there.

(ai-assisted, checked by me)

@FullStraing

Copy link
Copy Markdown
Author

Thanks for verifying the fix on 84 cases and for catching these two — both fixed: black formatting in series_utils.py (blank line after the import, single-line return) and the two-group pattern is now ([a-zA-Z])(\d) so it matches a row in test_string_data.

@ptimizeroracle ptimizeroracle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

thanks, the pattern change is right, ([a-zA-Z])(\d) gives that case a row to compare.

one thing left at 8157edf: line 426 of modin/pandas/series_utils.py, the blank line after from .dataframe import DataFrame, has 8 spaces on it. black --check (26.10.1) still wants to reformat the file because of it, and flake8 reports W293 on the same line. an empty line there clears both.

i did not rerun the tests on the three new commits, they only touch formatting and the test pattern.

(ai-assisted, checked by me)

@FullStraing

Copy link
Copy Markdown
Author

Thanks for catching that, @ptimizeroracle — line 426 in modin/pandas/series_utils.py is now completely empty, and black --check (26.10.1) passes on the file with flake8 W293 cleared. Please let me know if anything else is needed.

This branch has not been deployed

No deployments
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.

Series.str.extractall returns a Series instead of a DataFrame for a single capture group

2 participants