Skip to content

Commit

Permalink
Fix pandas 1.5+ FutureWarning in .str.split(..., expand=True) (#9704
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JacobHayes committed Nov 30, 2022
1 parent 49b516b commit 99123bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 99123bd

Please sign in to comment.