(data, names, any_string_dtype)
| 551 | ], |
| 552 | ) |
| 553 | def test_extractall_no_matches(data, names, any_string_dtype): |
| 554 | # GH19075 extractall with no matches should return a valid MultiIndex |
| 555 | n = len(data) |
| 556 | if len(names) == 1: |
| 557 | index = Index(range(n), name=names[0]) |
| 558 | else: |
| 559 | tuples = (tuple([i] * (n - 1)) for i in range(n)) |
| 560 | index = MultiIndex.from_tuples(tuples, names=names) |
| 561 | s = Series(data, name="series_name", index=index, dtype=any_string_dtype) |
| 562 | expected_index = MultiIndex.from_tuples([], names=((*names, "match"))) |
| 563 | |
| 564 | # one un-named group. |
| 565 | result = s.str.extractall("(z)") |
| 566 | expected = DataFrame(columns=range(1), index=expected_index, dtype=any_string_dtype) |
| 567 | tm.assert_frame_equal(result, expected, check_column_type=True) |
| 568 | |
| 569 | # two un-named groups. |
| 570 | result = s.str.extractall("(z)(z)") |
| 571 | expected = DataFrame(columns=range(2), index=expected_index, dtype=any_string_dtype) |
| 572 | tm.assert_frame_equal(result, expected, check_column_type=True) |
| 573 | |
| 574 | # one named group. |
| 575 | result = s.str.extractall("(?P<first>z)") |
| 576 | expected = DataFrame( |
| 577 | columns=["first"], index=expected_index, dtype=any_string_dtype |
| 578 | ) |
| 579 | tm.assert_frame_equal(result, expected) |
| 580 | |
| 581 | # two named groups. |
| 582 | result = s.str.extractall("(?P<first>z)(?P<second>z)") |
| 583 | expected = DataFrame( |
| 584 | columns=["first", "second"], index=expected_index, dtype=any_string_dtype |
| 585 | ) |
| 586 | tm.assert_frame_equal(result, expected) |
| 587 | |
| 588 | # one named, one un-named. |
| 589 | result = s.str.extractall("(z)(?P<second>z)") |
| 590 | expected = DataFrame( |
| 591 | columns=[0, "second"], index=expected_index, dtype=any_string_dtype |
| 592 | ) |
| 593 | tm.assert_frame_equal(result, expected) |
| 594 | |
| 595 | |
| 596 | def test_extractall_stringindex(any_string_dtype): |
nothing calls this directly
no test coverage detected