Skip to content

Commit e40098f

Browse files
committed
BUG: use _maybe_upcast and removes dup code. #1814
1 parent 54b54f8 commit e40098f

File tree

3 files changed

+2
-19
lines changed

3 files changed

+2
-19
lines changed

pandas/core/common.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -534,19 +534,6 @@ def ensure_float(arr):
534534

535535
return arr
536536

537-
def ensure_nansafe(arr):
538-
"""
539-
convert int to float
540-
convert bool to object
541-
"""
542-
if issubclass(arr.dtype.type, np.integer):
543-
arr = arr.astype(float)
544-
545-
elif issubclass(arr.dtype.type, np.bool_):
546-
arr = arr.astype(object)
547-
548-
return arr
549-
550537
def _mut_exclusive(arg1, arg2):
551538
if arg1 is not None and arg2 is not None:
552539
raise Exception('mutually exclusive arguments')

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3567,7 +3567,7 @@ def _shift_block(blk, indexer):
35673567
new_values = blk.values.take(indexer, axis=1)
35683568
# convert integer to float if necessary. need to do a lot more than
35693569
# that, handle boolean etc also
3570-
new_values = com.ensure_nansafe(new_values)
3570+
new_values = com._maybe_upcast(new_values)
35713571
if periods > 0:
35723572
new_values[:, :periods] = nan
35733573
else:

pandas/core/reshape.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,7 @@ def get_new_values(self):
157157
new_values = np.empty((length, result_width), dtype=values.dtype)
158158
new_mask = np.zeros((length, result_width), dtype=bool)
159159

160-
if issubclass(values.dtype.type, np.integer):
161-
new_values = new_values.astype(float)
162-
elif issubclass(values.dtype.type, np.bool_):
163-
new_values = new_values.astype(object)
164-
160+
new_values = com._maybe_upcast(new_values)
165161
new_values.fill(np.nan)
166162

167163
# is there a simpler / faster way of doing this?

0 commit comments

Comments
 (0)