BUG: where incorrectly coerces to str · Issue #9280 · pandas-dev/pandas (original) (raw)
Replacing some numeric values using where
affects to dtype unrelated to the condition.
s = pd.Series(np.random.randn(5))
u = s.where(s<0, 'X', axis=1)
u
#0 -1.01421184508
#1 X
#2 X
#3 -0.228117839063
#4 -0.393903873887
# dtype: object
The result looks OK, but internally coerced to all str
.
u.apply(type)
#0 <type 'str'>
#1 <type 'str'>
#2 <type 'str'>
#3 <type 'str'>
#4 <type 'str'>
# dtype: object