Skip to content

TST: Add any_string_dtype parameterization to test #44938

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
Dec 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/tests/strings/test_split_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ def test_split_with_name_index():
],
],
)
def test_partition_series_more_than_one_char(method, exp):
def test_partition_series_more_than_one_char(method, exp, any_string_dtype):
# https://github.com/pandas-dev/pandas/issues/23558
# more than one char
s = Series(["a__b__c", "c__d__e", np.nan, "f__g__h", None])
s = Series(["a__b__c", "c__d__e", np.nan, "f__g__h", None], dtype=any_string_dtype)
Copy link
Member

Choose a reason for hiding this comment

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

should this affect expected.dtype?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure cc @simonjayhawkins

We don't set the expected dtype in the rest of the tests.

Copy link
Member

Choose a reason for hiding this comment

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

only if we have expand=True (the default) we get a DataFrame with the columns with the same dtype otherwise the result is an object Series of tuples of python strings.

import pandas as pd

print(pd.__version__)

s = pd.Series(["a__b__c", "c__d__e", np.nan, "f__g__h", None], dtype="string[pyarrow]")
print(s)

result1= s.str.partition(sep = "__", expand=False)
print(result1)

result2 = s.str.partition(sep="__", expand=True)
print(result2)

print(result2.dtypes)

print(repr(result2[0].dtype))
1.4.0.dev0+1658.g05b85037ab
0    a__b__c
1    c__d__e
2       <NA>
3    f__g__h
4       <NA>
dtype: string
0    (a, __, b__c)
1    (c, __, d__e)
2             <NA>
3    (f, __, g__h)
4             <NA>
dtype: object
      0     1     2
0     a    __  b__c
1     c    __  d__e
2  <NA>  <NA>  <NA>
3     f    __  g__h
4  <NA>  <NA>  <NA>
0    string
1    string
2    string
dtype: object
string[pyarrow]

Copy link
Member

Choose a reason for hiding this comment

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

OK thanks.

result = getattr(s.str, method)("__", expand=False)
expected = Series(exp)
tm.assert_series_equal(result, expected)
Expand Down