Skip to content

Formatting of CategoricalIndex misaligned if NaNs are present #25061

@JustinZhengBC

Description

@JustinZhengBC
Contributor

Code Sample, a copy-pastable example if possible

>>> import pandas as pd
>>> pd.DataFrame([[1],[2]], index=pd.CategoricalIndex([1, pd.np.nan]))
      0
 1.0  1
NaN   2

Problem description

CategoricalIndex of a DataFrame is misaligned when printing if it contains NaN values.

Expected Output

>>> import pandas as pd
>>> pd.DataFrame([[1],[2]], index=pd.CategoricalIndex([1, pd.np.nan]))
      0
1.0   1
NaN   2

Output of pd.show_versions()

No module named 'dask'

INSTALLED VERSIONS

commit: da5f5eb
python: 3.6.6.final.0
python-bits: 64
OS: Darwin
OS-release: 18.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_CA.UTF-8
LOCALE: en_CA.UTF-8

pandas: 0.24.0.dev0+1684.gda5f5eb6c
pytest: 4.0.0
pip: 10.0.1
setuptools: 40.6.2
Cython: 0.29
numpy: 1.14.2
scipy: 1.1.0
pyarrow: 0.11.1
xarray: 0.11.0
IPython: 7.1.1
sphinx: 1.8.2
patsy: 0.5.0
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 3.0.1
openpyxl: 2.5.9
xlrd: 1.1.0
xlwt: 1.2.0
xlsxwriter: 1.1.2
lxml.etree: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.14
pymysql: 0.9.2
psycopg2: None
jinja2: 2.10
s3fs: 0.1.6
fastparquet: 0.2.1
pandas_gbq: None
pandas_datareader: None
gcsfs: 0.1.2

Activity

added this to the Contributions Welcome milestone on Jan 31, 2019
modified the milestones: Contributions Welcome, 0.25.0, 0.24.2 on Feb 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CategoricalCategorical Data TypeOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @jreback@TomAugspurger@JustinZhengBC

      Issue actions

        Formatting of CategoricalIndex misaligned if NaNs are present · Issue #25061 · pandas-dev/pandas