Skip to content

BUG/COMPAT: Series bool type not promoted to object when introducing NaNs #13034

Closed
@domspad

Description

@domspad

Code Sample, a copy-pastable example if possible

In [2]: import pandas as pd

In [3]: a = pd.Series([True,False,True])

In [4]: a
Out[4]: 
0     True
1    False
2     True
dtype: bool

In [6]: a[0] = pd.np.nan

In [7]: a
Out[7]: 
0    NaN
1    0.0
2    1.0
dtype: float64

Expected Output

based on type promotions mentioned here I would expect the series to get promoted to object to allow for NaNs.

When introducing NAs into an existing Series or DataFrame via reindex or some other means, boolean and integer types will be promoted to a different dtype in order to store the NAs. These are summarized by this table:

In [7]: a
Out[7]: 
0      NaN
1    False
2     True
dtype: object

output of pd.show_versions()

In [2]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Darwin
OS-release: 15.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US

pandas: 0.18.0
nose: 1.3.7
pip: 8.1.1
setuptools: 20.6.7
Cython: None
numpy: 1.10.4
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: 1.3.5
patsy: None
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.39.0```

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions