Skip to content

Commit f0ba9fd

Browse files
committed
Include _maybe_cast into _maybe_upcast_putmask inline, and fix Series.where test for Windows
1 parent d7e2785 commit f0ba9fd

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

pandas/core/common.py

+12-22
Original file line numberDiff line numberDiff line change
@@ -1081,26 +1081,6 @@ def _infer_dtype_from_scalar(val):
10811081
return dtype, val
10821082

10831083

1084-
def _maybe_cast(dtype, value):
1085-
"""
1086-
If `dtype` is date-like, then:
1087-
if `value` == nan, then convert to NaT
1088-
if `value` is an integer or integer array, convert to `dtype`
1089-
"""
1090-
if dtype in _DATELIKE_DTYPES:
1091-
if np.isscalar(value):
1092-
if isnull(value):
1093-
return tslib.iNaT
1094-
elif is_integer(value):
1095-
return np.array(value, dtype=dtype)
1096-
1097-
elif isinstance(value, np.ndarray):
1098-
if issubclass(dtype.type, np.integer):
1099-
return np.array(value, dtype=dtype)
1100-
1101-
return value
1102-
1103-
11041084
def _maybe_promote(dtype, fill_value=np.nan):
11051085

11061086
# if we passed an array here, determine the fill value by dtype
@@ -1186,8 +1166,18 @@ def _maybe_upcast_putmask(result, mask, other):
11861166
"""
11871167

11881168
if mask.any():
1189-
1190-
other = _maybe_cast(result.dtype, other)
1169+
# Two conversions for date-like dtypes that can't be done automatically
1170+
# in np.place:
1171+
# NaN -> NaT
1172+
# integer or integer array -> date-like array
1173+
if result.dtype in _DATELIKE_DTYPES:
1174+
if lib.isscalar(other):
1175+
if isnull(other):
1176+
other = tslib.iNaT
1177+
elif is_integer(other):
1178+
other = np.array(other, dtype=result.dtype)
1179+
elif is_integer_dtype(other):
1180+
other = np.array(other, dtype=result.dtype)
11911181

11921182
def changeit():
11931183

pandas/tests/test_series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ def test_where(self):
16891689
self.assertEqual(s.dtype, expected.dtype)
16901690

16911691
# GH 9731
1692-
s = Series(np.arange(10))
1692+
s = Series(np.arange(10), dtype='int64')
16931693
mask = s > 5
16941694
values = [2.5, 3.5, 4.5, 5.5]
16951695
s[mask] = values

0 commit comments

Comments
 (0)