-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
API: make hide_columns
and hide_index
have a consistent signature and function in Styler
#41266
API: make hide_columns
and hide_index
have a consistent signature and function in Styler
#41266
Conversation
pandas/io/formats/style_render.py
Outdated
|
||
if clabels: | ||
column_headers = [ | ||
if not self.hidden_colheads: |
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.
all that was changed here was to add if not self.hidden_colheads:
, the other additions and removals in comparison window are misleading.
hide_columns
and hide_index
have a consistent signature and function in Styler
hide_columns
and hide_index
have a consistent signature and function in Styler
ok i undestand what you are doing, but this is still a very confusing api. we want to support
can you show me what you would write for these? |
sure.. The mechanics seem to be in place to do this quite easily, it just needs steering on the best API implementation.. |
ok your example looks fine. I am confused by the |
I removed the |
pandas/io/formats/style.py
Outdated
|
||
Parameters | ||
---------- | ||
subset : IndexSlice |
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 is pretty confusing, why is this not just a list-like (of row labels)? e.g. similar to the argument for .dropna()
for example
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.
changed. pls review
pandas/io/formats/style.py
Outdated
- if ``subset`` is ``None`` then the entire column headers row will be hidden | ||
whilst the data-values remain visible. | ||
- if a ``subset`` is given then those specific columns, including the | ||
data-values will be hidden, whilst the column headers row remains visible. | ||
|
||
Parameters | ||
---------- | ||
subset : IndexSlice |
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.
same comment as above
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.
now I wouldn't object to also allowing an IndexSlice here (in addition to a list-like of columns labels)
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.
changed. pls review
-------- | ||
Hide column headers and retain the data values: | ||
|
||
>>> midx = pd.MultiIndex.from_product([["x", "y"], ["a", "b", "c"]]) |
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.
can you show an example first that has a single level index.
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.
added
pandas/io/formats/style_render.py
Outdated
@@ -98,6 +98,8 @@ def __init__( | |||
|
|||
# add rendering variables | |||
self.hidden_index: bool = False | |||
self.hidden_rows: Sequence[int] = [] |
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.
can you change the impl to use the same nomenclature, e.g. hidden_index, hidden_columns (or similar)
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.
Can you give your input to the suggestion below:
self.hide_index_: bool
self.hide_columns_: bool
self.hidden_indexes: Sequence[int]
self.hidden_columns: Sequence[int]
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.
updated (used rows instead of indexes)
…ns_and_index # Conflicts: # pandas/io/formats/style.py # pandas/io/formats/style_render.py
…ns_and_index # Conflicts: # pandas/io/formats/style.py # pandas/tests/io/formats/style/test_style.py
…ns_and_index # Conflicts: # pandas/io/formats/style.py
…ns_and_index # Conflicts: # pandas/io/formats/style_render.py
…x` have a consistent signature and function in `Styler`
this is good, thanks @attack68 as a followup can you make sure that these methods are in the api ref & also we have sufficient docs in the notebook (the doc-strings are great obviously), but generally give an update in the notebook (its not of course necessary to add everything, but major things like this are good). |
@meeseeksdev backport 1.3.x |
Something went wrong ... Please have a look at my logs. |
…consistent signature and function in `Styler` (#42041) Co-authored-by: attack68 <24256554+attack68@users.noreply.github.com>
… and function in `Styler` (pandas-dev#41266)
Hi @attack68. I'm working on issue #42674 and I found some doctests with expected results different from the real results (at least in my tests). See the examples below:
As you can see below, the values Is there any reason these results are divergent? Obs.: There are some other doctests in the same method after the one mentioned above, which present the same problem. |
This closes #41158 (which is an alternative PR for similar functionality)
Currently
hide_index()
andhide_columns(subset)
have similar signatures but different operations. One hides the index whilst showing the data-rows, and the other hides data-columns whilst showing the column-headers row.This PR
subset
keyword to give:hide_index(subset=None)
.hide_columns(subset=None)
.When
subset
is None the function now operates to hide the entire index, or entire column headers row respectively.When
subset
is not None it operates to selectively hide the given rows or columns respectively, keeping the index or column headers row.We also add theshow
keyword to allow the method to operate inversely.@jreback I think you will prefer this over the
hide_values
andhide_headers
methods suggested in #41158 since this re-uses the existing methods with minimal changes but tries to align their consistency. It is also fully backwards compatible.