Skip to content

DOC: Fixing EX01 - Added examples #54127

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

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.errors.UnsupportedFunctionCall \
pandas.test \
pandas.NaT \
pandas.io.formats.style.Styler.to_html \
pandas.read_feather \
pandas.DataFrame.to_feather \
pandas.read_parquet \
Expand All @@ -112,15 +111,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.DatetimeIndex.snap \
pandas.api.indexers.BaseIndexer \
pandas.api.indexers.VariableOffsetWindowIndexer \
pandas.io.formats.style.Styler.set_caption \
pandas.io.formats.style.Styler.set_sticky \
pandas.io.formats.style.Styler.set_uuid \
pandas.io.formats.style.Styler.clear \
pandas.io.formats.style.Styler.highlight_null \
pandas.io.formats.style.Styler.highlight_max \
pandas.io.formats.style.Styler.highlight_min \
pandas.io.formats.style.Styler.bar \
pandas.io.formats.style.Styler.to_string \
pandas.api.extensions.ExtensionDtype \
pandas.api.extensions.ExtensionArray \
pandas.arrays.PandasArray \
Expand Down
97 changes: 97 additions & 0 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,21 @@ def to_html(
See Also
--------
DataFrame.to_html: Write a DataFrame to a file, buffer or string in HTML format.

Examples
--------
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
>>> print(df.style.to_html()) # doctest: +SKIP
<style type="text/css">
</style>
<table id="T_1e78e">
<thead>
<tr>
<th class="blank level0" >&nbsp;</th>
<th id="T_1e78e_level0_col0" class="col_heading level0 col0" >A</th>
<th id="T_1e78e_level0_col1" class="col_heading level0 col1" >B</th>
</tr>
...
"""
obj = self._copy(deepcopy=True) # manipulate table_styles on obj, not self

Expand Down Expand Up @@ -1419,6 +1434,12 @@ def to_string(
-------
str or None
If `buf` is None, returns the result as a string. Otherwise returns `None`.

Examples
--------
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
>>> df.style.to_string()
' A B\\n0 1 3\\n1 2 4\\n'
"""
obj = self._copy(deepcopy=True)

Expand Down Expand Up @@ -1650,6 +1671,21 @@ def clear(self) -> None:
Reset the ``Styler``, removing any previously applied styles.

Returns None.

Examples
--------
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, np.nan]})

After any added style:

>>> df.style.highlight_null(color='yellow') # doctest: +SKIP

Remove it with:

>>> df.style.clear() # doctest: +SKIP

Please see:
`Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
"""
# create default GH 40675
clean_copy = Styler(self.data, uuid=self.uuid)
Expand Down Expand Up @@ -2257,6 +2293,22 @@ def set_uuid(self, uuid: str) -> Styler:
Almost all HTML elements within the table, and including the ``<table>`` element
are assigned ``id`` attributes. The format is ``T_uuid_<extra>`` where
``<extra>`` is typically a more specific identifier, such as ``row1_col2``.

Examples
--------
>>> df = pd.DataFrame([[1, 2], [3, 4]], index=['A', 'B'], columns=['c1', 'c2'])

You can get the `id` attributes with the following:

>>> print((df).style.to_html()) # doctest: +SKIP

To add a title to column `c1`, its `id` is T_20a7d_level0_col0:

>>> df.style.set_uuid("T_20a7d_level0_col0")
... .set_caption("Test") # doctest: +SKIP

Please see:
`Table visualization <../../user_guide/style.ipynb>`_ for more examples.
"""
self.uuid = uuid
return self
Expand All @@ -2275,6 +2327,14 @@ def set_caption(self, caption: str | tuple | list) -> Styler:
Returns
-------
Styler

Examples
--------
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
>>> df.style.set_caption("test") # doctest: +SKIP

Please see:
`Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
"""
msg = "`caption` must be either a string or 2-tuple of strings."
if isinstance(caption, (list, tuple)):
Expand Down Expand Up @@ -2323,6 +2383,14 @@ def set_sticky(
- `styler.set_sticky(axis="columns").hide(axis="columns")`

may produce strange behaviour due to CSS controls with missing elements.

Examples
--------
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
>>> df.style.set_sticky(axis="index") # doctest: +SKIP

Please see:
`Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
"""
axis = self.data._get_axis_number(axis)
obj = self.data.index if axis == 0 else self.data.columns
Expand Down Expand Up @@ -3073,6 +3141,11 @@ def bar( # pylint: disable=disallowed-name
This section of the user guide:
`Table Visualization <../../user_guide/style.ipynb>`_ gives
a number of examples for different settings and color coordination.

Examples
--------
>>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
>>> df.style.bar(subset=['A'], color='gray') # doctest: +SKIP
"""
if color is None and cmap is None:
color = "#d65f5f"
Expand Down Expand Up @@ -3147,6 +3220,14 @@ def highlight_null(
Styler.highlight_min: Highlight the minimum with a style.
Styler.highlight_between: Highlight a defined range with a style.
Styler.highlight_quantile: Highlight values defined by a quantile with a style.

Examples
--------
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, np.nan]})
>>> df.style.highlight_null(color='yellow') # doctest: +SKIP

Please see:
`Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
"""

def f(data: DataFrame, props: str) -> np.ndarray:
Expand Down Expand Up @@ -3193,6 +3274,14 @@ def highlight_max(
Styler.highlight_min: Highlight the minimum with a style.
Styler.highlight_between: Highlight a defined range with a style.
Styler.highlight_quantile: Highlight values defined by a quantile with a style.

Examples
--------
>>> df = pd.DataFrame({'A': [2, 1], 'B': [3, 4]})
>>> df.style.highlight_max(color='yellow') # doctest: +SKIP

Please see:
`Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
"""

if props is None:
Expand Down Expand Up @@ -3241,6 +3330,14 @@ def highlight_min(
Styler.highlight_max: Highlight the maximum with a style.
Styler.highlight_between: Highlight a defined range with a style.
Styler.highlight_quantile: Highlight values defined by a quantile with a style.

Examples
--------
>>> df = pd.DataFrame({'A': [2, 1], 'B': [3, 4]})
>>> df.style.highlight_min(color='yellow') # doctest: +SKIP

Please see:
`Table Visualization <../../user_guide/style.ipynb>`_ for more examples.
"""

if props is None:
Expand Down