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

Enable to assign list. #1644

Merged
merged 1 commit into from
Jul 10, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions databricks/koalas/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10032,6 +10032,22 @@ def assign_columns(kdf, this_column_labels, that_column_labels):
yield (kdf._kser_for(this_label), this_label)

kdf = align_diff_frames(assign_columns, self, value, fillna=False, how="left")
elif isinstance(value, list):
if len(self) != len(value):
raise ValueError("Length of values does not match length of index")

# TODO: avoid using default index?
with option_context(
"compute.default_index_type",
"distributed-sequence",
"compute.ops_on_diff_frames",
True,
):
kdf = self.reset_index()
kdf[key] = ks.DataFrame(value)
kdf = kdf.set_index(kdf.columns[: len(self._internal.index_map)])
kdf.index.names = self.index.names

elif isinstance(key, list):
assert isinstance(value, DataFrame)
# Same DataFrames.
Expand Down
15 changes: 15 additions & 0 deletions databricks/koalas/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ def test_inplace(self):
self.assert_eq(kdf, pdf)
self.assert_eq(kser, pser)

def test_assign_list(self):
pdf, kdf = self.df_pair

pser = pdf.a
kser = kdf.a

pdf["x"] = [10, 20, 30, 40, 50, 60, 70, 80, 90]
kdf["x"] = [10, 20, 30, 40, 50, 60, 70, 80, 90]

self.assert_eq(kdf.sort_index(), pdf.sort_index())
self.assert_eq(kser, pser)

with self.assertRaisesRegex(ValueError, "Length of values does not match length of index"):
kdf["z"] = [10, 20, 30, 40, 50, 60, 70, 80]

def test_dataframe_multiindex_columns(self):
pdf = pd.DataFrame(
{
Expand Down