Skip to content

Commit 135f4b1

Browse files
committed
PERF: get_dummies return bool columns
Make get_dummies() return columns of dtype=bool instead of np.float64 BUG: dtype compat with get_dummies pandas-dev#8725 pandas-dev#8725 Since all the point of this method is to return binary features there's no point to waste RAM and represent them using floats
1 parent e0a2e3b commit 135f4b1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/core/reshape.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,10 @@ def get_empty_Frame(data, sparse):
11631163
sparse_index=IntIndex(N, ixs), fill_value=0)
11641164
sparse_series[col] = SparseSeries(data=sarr, index=index)
11651165

1166-
return SparseDataFrame(sparse_series, index=index, columns=dummy_cols)
1166+
return SparseDataFrame(sparse_series, index=index, columns=dummy_cols, dtype=bool)
11671167

11681168
else:
1169-
dummy_mat = np.eye(number_of_cols).take(codes, axis=0)
1169+
dummy_mat = np.eye(number_of_cols, dtype=bool).take(codes, axis=0)
11701170

11711171
if not dummy_na:
11721172
# reset NaN GH4446
@@ -1176,7 +1176,7 @@ def get_empty_Frame(data, sparse):
11761176
# remove first GH12042
11771177
dummy_mat = dummy_mat[:, 1:]
11781178
dummy_cols = dummy_cols[1:]
1179-
return DataFrame(dummy_mat, index=index, columns=dummy_cols)
1179+
return DataFrame(dummy_mat, index=index, columns=dummy_cols, dtype=bool)
11801180

11811181

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

0 commit comments

Comments
 (0)