Skip to content

Commit 51cd9d0

Browse files
committed
CLN: move dtype logic to internal function in get_dummies
1 parent e60f125 commit 51cd9d0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pandas/core/reshape/reshape.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,6 @@ def get_dummies(data, prefix=None, prefix_sep='_', dummy_na=False,
801801
from pandas.core.reshape.concat import concat
802802
from itertools import cycle
803803

804-
if dtype is None:
805-
dtype = np.uint8
806-
807-
if is_object_dtype(dtype):
808-
raise ValueError("dtype=object is not a valid dtype for get_dummies")
809-
810804
if isinstance(data, DataFrame):
811805
# determine columns being encoded
812806

@@ -864,10 +858,18 @@ def check_len(item, name):
864858

865859

866860
def _get_dummies_1d(data, prefix, prefix_sep='_', dummy_na=False,
867-
sparse=False, drop_first=False, dtype=np.uint8):
861+
sparse=False, drop_first=False, dtype=None):
868862
# Series avoids inconsistent NaN handling
869863
codes, levels = _factorize_from_iterable(Series(data))
870864

865+
if dtype is None:
866+
dtype = np.uint8
867+
else:
868+
dtype = np.dtype(dtype)
869+
870+
if is_object_dtype(dtype):
871+
raise ValueError("dtype=object is not a valid dtype for get_dummies")
872+
871873
def get_empty_Frame(data, sparse):
872874
if isinstance(data, Series):
873875
index = data.index

0 commit comments

Comments
 (0)