|
17 | 17 | is_integer, is_complex, is_float_dtype,
|
18 | 18 | is_complex_dtype, is_integer_dtype,
|
19 | 19 | is_bool_dtype, is_object_dtype,
|
| 20 | + is_numeric_dtype, |
20 | 21 | is_datetime64_dtype, is_timedelta64_dtype,
|
21 | 22 | is_datetime_or_timedelta_dtype,
|
22 | 23 | is_int_or_datetime_dtype, is_any_int_dtype)
|
@@ -638,11 +639,15 @@ def _maybe_null_out(result, axis, mask):
|
638 | 639 | if axis is not None and getattr(result, 'ndim', False):
|
639 | 640 | null_mask = (mask.shape[axis] - mask.sum(axis)) == 0
|
640 | 641 | if np.any(null_mask):
|
641 |
| - if np.iscomplexobj(result): |
642 |
| - result = result.astype('c16') |
| 642 | + if is_numeric_dtype(result): |
| 643 | + if np.iscomplexobj(result): |
| 644 | + result = result.astype('c16') |
| 645 | + else: |
| 646 | + result = result.astype('f8') |
| 647 | + result[null_mask] = np.nan |
643 | 648 | else:
|
644 |
| - result = result.astype('f8') |
645 |
| - result[null_mask] = np.nan |
| 649 | + # GH12941, use None to auto cast null |
| 650 | + result[null_mask] = None |
646 | 651 | elif result is not tslib.NaT:
|
647 | 652 | null_mask = mask.size - mask.sum()
|
648 | 653 | if null_mask == 0:
|
|
0 commit comments