FLAML icon indicating copy to clipboard operation
FLAML copied to clipboard

Support y as a single-column pd.DataFrame

Open EgorKraevTransferwise opened this issue 3 years ago • 3 comments

When using FLAML(task="classification") as a component model in EconML/DoWhy, sometimes it gets called with y being a pd.DataFrame with a single column, and that throws an error as it only expects a pd.Series or np.ndarray.

Can we please also support dataframes with a single column, in which case we'd take that column as y?

Currently I monkey-patch around it, but it would be nicer if it just handled it.

Happy to do the PR myself if you tell me where in the code the changes should live :)

EgorKraevTransferwise avatar Jul 18 '22 15:07 EgorKraevTransferwise

Great suggestion. These are the relevant places to be changed:

https://github.com/microsoft/FLAML/blob/a64956a7c8f98db6a7de7e8cc5d0ce53e9c86a03/flaml/automl.py#L1052 https://github.com/microsoft/FLAML/blob/a64956a7c8f98db6a7de7e8cc5d0ce53e9c86a03/flaml/automl.py#L1164 allow one-column dataframe and convert to series.

https://github.com/microsoft/FLAML/blob/a64956a7c8f98db6a7de7e8cc5d0ce53e9c86a03/flaml/automl.py#L1560 https://github.com/microsoft/FLAML/blob/a64956a7c8f98db6a7de7e8cc5d0ce53e9c86a03/flaml/automl.py#L2086 https://github.com/microsoft/FLAML/blob/a64956a7c8f98db6a7de7e8cc5d0ce53e9c86a03/flaml/automl.py#L2178 update docstr.

@qingyun-wu @ekzhu Please comment if I missed anything.

sonichi avatar Jul 18 '22 17:07 sonichi

Thanks! Would I not want to convert the one-column dataframe to a column before using it, or will that happen automatically if it passes the assertions?

EgorKraevTransferwise avatar Jul 20 '22 09:07 EgorKraevTransferwise

Thanks! Would I not want to convert the one-column dataframe to a column before using it, or will that happen automatically if it passes the assertions?

Please convert it. It won't happen automatically. Thanks.

sonichi avatar Jul 20 '22 13:07 sonichi