Skip to content

Change get_dummies() to return columns of dtype=bool instead of np.float64 #13283

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

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 5 additions & 5 deletions pandas/core/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,14 +1159,14 @@ def get_empty_Frame(data, sparse):
sp_indices = sp_indices[1:]
dummy_cols = dummy_cols[1:]
for col, ixs in zip(dummy_cols, sp_indices):
sarr = SparseArray(np.ones(len(ixs)),
sarr = SparseArray(np.ones(len(ixs), dtype=bool),
sparse_index=IntIndex(N, ixs), fill_value=0)
sparse_series[col] = SparseSeries(data=sarr, index=index)
sparse_series[col] = SparseSeries(data=sarr, index=index, dtype=bool)

return SparseDataFrame(sparse_series, index=index, columns=dummy_cols)
return SparseDataFrame(sparse_series, index=index, columns=dummy_cols, dtype=bool)

else:
dummy_mat = np.eye(number_of_cols).take(codes, axis=0)
dummy_mat = np.eye(number_of_cols, dtype=bool).take(codes, axis=0)

if not dummy_na:
# reset NaN GH4446
Expand All @@ -1176,7 +1176,7 @@ def get_empty_Frame(data, sparse):
# remove first GH12042
dummy_mat = dummy_mat[:, 1:]
dummy_cols = dummy_cols[1:]
return DataFrame(dummy_mat, index=index, columns=dummy_cols)
return DataFrame(dummy_mat, index=index, columns=dummy_cols, dtype=bool)


def make_axis_dummies(frame, axis='minor', transform=None):
Expand Down