str.contains - returns series of zeroes instead of series of bools when all values are NaNs. · Issue #9184 · pandas-dev/pandas (original) (raw)

import pandas as pd
df = pd.DataFrame({'a': ['x', 'y', 'z'], 'b': [np.nan, np.nan, np.nan]})

Applying to string column - produces correct result:

df['a'].str.contains('c', na=False)
0    False
1    False
2    False
Name: a, dtype: bool

Applying to float column - returns zeroes instead of bools and return type is float64:

df['b'].str.contains('c', na=False)
0    0
1    0
2    0
Name: b, dtype: float64