Skip to content

BUG: MultiIndex.__repr__ is broken when display.max_seq_items = 1 #38415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
galipremsagar opened this issue Dec 11, 2020 · 4 comments · Fixed by #38443
Closed
2 of 3 tasks

BUG: MultiIndex.__repr__ is broken when display.max_seq_items = 1 #38415

galipremsagar opened this issue Dec 11, 2020 · 4 comments · Fixed by #38443
Assignees
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@galipremsagar
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

In[11]: pd.set_option("display.max_seq_items", 2)
In[12]: pd.MultiIndex.from_tuples(tuples)
Out[12]: 
MultiIndex([(1,  'red'),
            ...
            (2, 'blue')],
           length=40)
In[13]: tuples = [(1, 'red'), (1, 'blue'), (2, 'red'), (2, 'blue')]
In[14]: pd.MultiIndex.from_tuples(tuples)
Out[14]: 
MultiIndex([(1,  'red'),
            ...
            (2, 'blue')],
           length=4)
In[15]: pd.set_option("display.max_seq_items", 1)
In[16]: pd.MultiIndex.from_tuples(tuples)
Out[16]: 
MultiIndex([...
            (1,  'red'),
            (1, 'blue'),
            (2,  'red'),
            (2, 'blue')],
           length=4)

Problem description

The output of MultiIndex.__repr__ is dependent on display.max_seq_items, the output is correct for different values of max_seq_items except when it is set to 1. When it is set to 1, the entire records in MultiIndex are being printed and also "..." are being prepended to the data output.

Expected Output

In[12]: pd.MultiIndex.from_tuples(tuples)
Out[12]: 
MultiIndex([(1,  'red'),
            ...],
           length=40)

Output of pd.show_versions()

INSTALLED VERSIONS

commit : b5958ee
python : 3.7.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-53-generic
Version : #59-Ubuntu SMP Wed Oct 21 09:38:44 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.5
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1
pip : 20.3.1
setuptools : 49.6.0.post20201009
Cython : 0.29.21
pytest : 6.1.2
hypothesis : 5.43.3
sphinx : 3.3.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.4
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.52.0

@galipremsagar galipremsagar added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 11, 2020
@skvrahul
Copy link
Contributor

take

@skvrahul
Copy link
Contributor

Looks to be caused by these lines in pandas/io/formats/printing.py

if n > max_seq_items:
n = min(max_seq_items // 2, 10)
head = [formatter(x) for x in obj[:n]]
tail = [formatter(x) for x in obj[-n:]]
else:
head = []
tail = [formatter(x) for x in obj]
.

What is the expected behaviour when max_seq_items is set to 0? Is the number of items in the summary then unbounded?

@rhshadrach
Copy link
Member

@skvrahul Above the block you linked, there is logic for handling when n is 0 or 1. It seems these should also handle when max_seq_items is 0 or 1.

@rhshadrach rhshadrach added Output-Formatting __repr__ of pandas objects, to_string and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 12, 2020
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Dec 12, 2020
@skvrahul
Copy link
Contributor

Got it. Will try making the change and put out a PR soon!

@jreback jreback modified the milestones: Contributions Welcome, 1.3 Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants