woodwork icon indicating copy to clipboard operation
woodwork copied to clipboard

Support multiple column assignment via woodwork accessor

Open ParthivNaresh opened this issue 2 years ago • 0 comments

Currently if a user attempts to assign multiple columns using the woodwork accessor, an error is thrown.

def test_multiple_assignment():
    df = pd.DataFrame()
    df["ints"] = [i for i in range(100)]
    df["bools"] = [True, False, True, False] * 25
    df["datetime"] = pd.date_range("1/1/21", periods=100)

    df_ = pd.DataFrame()
    df_["ints_"] = [f"{i * 2}" for i in range(100)]
    df_["bools_"] = [f"{i * 5}" for i in range(100)]

    df.ww.init()
    df.ww[["ints", "bools"]] = df_
---------------------------------------
ValueError: New column must be of Series type

Whereas

def test_multiple_assignment():
    df = pd.DataFrame()
    df["ints"] = [i for i in range(100)]
    df["bools"] = [True, False, True, False] * 25
    df["datetime"] = pd.date_range("1/1/21", periods=100)

    df_ = pd.DataFrame()
    df_["ints_"] = [f"{i * 2}" for i in range(100)]
    df_["bools_"] = [f"{i * 5}" for i in range(100)]

    df[["ints", "bools"]] = df_

yields the correct assignment

ParthivNaresh avatar Aug 06 '22 13:08 ParthivNaresh