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 assigning Series to column when ddf.columns.min() raises #9485

Merged
merged 1 commit into from Sep 13, 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
13 changes: 8 additions & 5 deletions dask/dataframe/core.py
Expand Up @@ -6017,15 +6017,18 @@ def is_broadcastable(dfs, s):
"""
This Series is broadcastable against another dataframe in the sequence
"""

def compare(s, df):
try:
return s.divisions == (df.columns.min(), df.columns.max())
except TypeError:
return False

return (
isinstance(s, Series)
and s.npartitions == 1
and s.known_divisions
and any(
s.divisions == (df.columns.min(), df.columns.max())
for df in dfs
if isinstance(df, DataFrame)
)
and any(compare(s, df) for df in dfs if isinstance(df, DataFrame))
)


Expand Down
8 changes: 8 additions & 0 deletions dask/dataframe/tests/test_dataframe.py
Expand Up @@ -1623,6 +1623,14 @@ def test_assign_dtypes():
)


def test_assign_pandas_series():
# Make sure we handle when `df.columns.min()` raises TypeError
df = pd.DataFrame({"a": [1, 2], 1: [5, 6]})
ddf = dd.from_pandas(df, npartitions=2)
ddf = ddf.assign(c=df["a"])
assert_eq(ddf, df.assign(c=df["a"]))


def test_map():
df = pd.DataFrame(
{"a": range(9), "b": [4, 5, 6, 1, 2, 3, 0, 0, 0]},
Expand Down