Pandas: BUG?: can't print the head of a sparse dataframe in 0.21.0

Created on 28 Nov 2017  路  3Comments  路  Source: pandas-dev/pandas

import pandas as pd
df = pd.DataFrame([['a','b'],['c','d']])
S = pd.get_dummies(df, columns=[1], sparse=True)
print(S.head(1))

Problem description

You get:

TypeError: values must be SparseArray

However in pandas 0.20.3 it works OK

Expected Output

In [4]: print(S.head(1))

   0  1_b  1_d
0  a    1    0

Output of pd.show_versions()

pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-98-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.21.0
pytest: None
pip: 9.0.1
setuptools: 36.7.1
Cython: 0.27.3
numpy: 1.13.3
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 1.0.2
lxml: None
bs4: 4.6.0
html5lib: 1.0b10
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Bug Output-Formatting Sparse

Most helpful comment

cc @kernc
cc @Licht-T

seems buggy

All 3 comments

cc @kernc
cc @Licht-T

seems buggy

xref to #16874 which is the underlying issue, though maybe not the cause of this particular.

This will be fixed by https://github.com/pandas-dev/pandas/pull/18924#issuecomment-361904871

I will add to that PR

Was this page helpful?
0 / 5 - 0 ratings