Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Updated Reshape.py to validate columns in get_dummies
Added validation for the argument passed to columns
  • Loading branch information
R1j1t committed Sep 16, 2019
commit 87fa4ea4b702bbff917ea06f3d56a313bc0baa13
2 changes: 2 additions & 0 deletions pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,8 @@ def get_dummies(
# determine columns being encoded
if columns is None:
data_to_encode = data.select_dtypes(include=dtypes_to_encode)
elif not is_list_like(columns):
raise TypeError("Input must be a list-like of list-likes")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message should state which parameter is incorrect (columns?)

And is it supposed to be a list-like of list-likes? This block is just checking that it's a sequence, but not making any assertion about what each element is.

Copy link
Contributor Author

@R1j1t R1j1t Sep 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message should state which parameter is incorrect

I have updated the Error message based on your comment but let me point out this code which was the reason I did not update the error message.

making any assertion about what each element is.

I think this is out of scope because for all the functions definitions (involving list-like object as parameters ) I referred to in pandas, none of them had this check. @jbrockmendel Is this something which should have been checked?

else:
data_to_encode = data[columns]

Expand Down