-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
Shorter MultiIndex representation #21145
Conversation
d0eb354
to
4fd6884
Compare
Hello @topper-123! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on May 21, 2018 at 19:59 Hours UTC |
Codecov Report
@@ Coverage Diff @@
## master #21145 +/- ##
==========================================
- Coverage 91.84% 91.84% -0.01%
==========================================
Files 153 153
Lines 49502 49512 +10
==========================================
+ Hits 45463 45472 +9
- Misses 4039 4040 +1
Continue to review full report at Codecov.
|
4fd6884
to
e822b77
Compare
@@ -609,11 +609,28 @@ def _format_attrs(self): | |||
""" | |||
Return a list of tuples of the (attr,formatted_value) | |||
""" | |||
def to_string_helper(obj, attr_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of creating new functions, can you simply override _format_attrs
or as appropriate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper is inside _format_attrs
, so it’s not visible other places.
Not what you meant, but it could be placed in top level indexes/base.py
as eg. _index_to_string
, so others could use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so move this to pandas.io.formats.printing and make as generic as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you are changing the repr and no tests broke that seems to be a problem.
yes this parameter needs to be used to control the len |
>>> pd.options.display.max_seq_items
100
>>> idx=range(101)
>>> pd.MultiIndex.from_arrays([idx, idx]) # abbreviates
MultiIndex(levels=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
...
91, 92, 93, 94, 95, 96, 97, 98, 99, 100],
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
...
91, 92, 93, 94, 95, 96, 97, 98, 99, 100],
],
labels=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
...
91, 92, 93, 94, 95, 96, 97, 98, 99, 100],
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
...
91, 92, 93, 94, 95, 96, 97, 98, 99, 100],
])
>>> idx=range(100)
>>> pd.MultiIndex.from_arrays([idx, idx]) # doesn't abbreviate
MultiIndex(levels=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
],
labels=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
]) If |
152e057
to
8b70d96
Compare
8b70d96
to
00c2297
Compare
Is this ok? |
@@ -15,6 +15,36 @@ and bug fixes. We recommend that all users upgrade to this version. | |||
New features | |||
~~~~~~~~~~~~ | |||
|
|||
.. _whatsnew_0231.enhancements.new_multi_index_repr_: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to 0.24.0
@@ -609,11 +609,28 @@ def _format_attrs(self): | |||
""" | |||
Return a list of tuples of the (attr,formatted_value) | |||
""" | |||
def to_string_helper(obj, attr_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so move this to pandas.io.formats.printing and make as generic as possible.
|
||
def test_repr(self): | ||
# GH21145 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set the context manager for width here (so need multiple tests for this), e.g. with a small value then a large value to see how it works on different settings.
|
||
.. ipython:: python | ||
|
||
index1=range(1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can make this section a bit shorter overall.
slow to print and make the console output difficult to navigate. | ||
|
||
Outputting of ``MultiIndex`` instances now has limits to the number of levels | ||
and labels shown ((:issue:`21145`): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra paren here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be the issue number
slow to print and make the console output difficult to navigate. | ||
|
||
Outputting of ``MultiIndex`` instances now has limits to the number of levels | ||
and labels shown ((:issue:`21145`): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be the issue number
Closed in favor of #22511. |
git diff upstream/master -u -- "*.py" | flake8 --diff
MultiIndex can currently have quite long repr output, which may also take a long time to print.
This PR makes the MultiIndex repr output similar in style to other Index reprs. An alternative would be to output
labels
andlevels
by supplyingpd.options.display.max_seq_items
toibase.default_pprint
, but IMO this is better, as it's more similar to other axis repr's.Example with few items in index
Example with many items in index
If this approach is ok, I can write up whatsnew, tests etc. but would appreciate feedback before I do that.
EDIT: tests and whatsnew added.