Skip to content
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

Fix pandas 1.5+ FutureWarning in .str.split(..., expand=True) #9704

Merged
merged 2 commits into from Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dask/dataframe/accessor.py
Expand Up @@ -265,7 +265,7 @@ def _split(self, method, pat=None, n=-1, expand=False):
delimiter = " " if pat is None else pat
meta = self._series._meta._constructor(
[delimiter.join(["a"] * (n + 1))],
index=self._series._meta_nonempty[:1].index,
index=self._series._meta_nonempty.iloc[:1].index,
)
meta = getattr(meta.str, method)(n=n, expand=expand, pat=pat)
else:
Expand Down
11 changes: 11 additions & 0 deletions dask/dataframe/tests/test_accessors.py
Expand Up @@ -294,6 +294,17 @@ def test_str_accessor_split_expand_more_columns():
ds.str.split(n=10, expand=True).compute()


@pytest.mark.parametrize("index", [None, [0]], ids=["range_index", "other index"])
def test_str_split_no_warning(index):
df = pd.DataFrame({"a": ["a\nb"]}, index=index)
ddf = dd.from_pandas(df, npartitions=1)

pd_a = df["a"].str.split("\n", n=1, expand=True)
dd_a = ddf["a"].str.split("\n", n=1, expand=True)

assert_eq(dd_a, pd_a)


def test_string_nullable_types(df_ddf):
df, ddf = df_ddf
assert_eq(ddf.string_col.str.count("A"), df.string_col.str.count("A"))
Expand Down