Skip to content

Conversation

@attack68
Copy link
Contributor

For showing and hiding columns/rows Styler currently has two methods:

  • .hide_columns(subset): which hides a selection of columns and the associated data values.
  • .hide_index(): which hides the index keys completely and displays all the data values.

This PR adds a .hide_values(subset, axis, show) method, which is a superset of .hide_columns. It allows the same functionality to operate row-wise, and adds the kwarg show which allows an inverse method, exclusively showing instead of hiding.

Follow-on:

Option 1

Keep .hide_values(subset, axis, show) as is and deprecate .hide_columns.

Option 2

Make ._hide_values(subset, axis, show) a private module and include/add the public methods:

- `hide_columns`      = `_hide_values(subset=subset, axis="columns", show=False)`.
- `hide_rows`         = `_hide_values(subset=subset, axis="index", show=False)`.
- `show_columns`      = `_hide_values(subset=subset, axis="columns", show=True)`.
- `show_rows`         = `_hide_values(subset=subset, axis="index", show=True)`.

@jreback jreback added the Styler conditional formatting using DataFrame.style label Apr 30, 2021
self.hidden_columns = hcols # type: ignore[assignment]
return self.hide_values(subset)

def hide_values(self, subset, axis: Axis = "columns", show: bool = False) -> Styler:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i find this a very confusing name, hide_axis is more appropriate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trick is to distinguish between the cases of:

a) hiding select rows or columns of data (whilst other index keys or column headers are visible),
b) or displaying the data values but just hiding the index or column headers row in their entirety.

Currently hide_columns does a) whilst hide_index does b). The complete idea was that:

i) hide_values would do a) for either the index or columns axes.
ii) hide_headers (a new method) would do b) for either the index or columns axes.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback i created an alternative in #41266 which seeks to achieve the same functionality in a different way re-using exiting methods and kwargs. Close this PR if you prefer the alternative,

return self.hide_values(subset)

def hide_values(self, subset, axis: Axis = "columns", show: bool = False) -> Styler:
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wouldn't make this user visible instead prefer hide_index, hide_columns (this can be the impl)

@jreback jreback added the API - Consistency Internal Consistency of API/Behavior label Apr 30, 2021
@attack68
Copy link
Contributor Author

attack68 commented May 7, 2021

closing this is favour of #41266 for now.

@attack68 attack68 closed this May 7, 2021
@jreback jreback added this to the 1.3 milestone Jun 16, 2021
@attack68 attack68 deleted the depr_hide_columns branch July 5, 2021 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API - Consistency Internal Consistency of API/Behavior Styler conditional formatting using DataFrame.style

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants