Skip to content

Commit

Permalink
REF/API: Styler->HTMLStyler
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed May 18, 2016
1 parent 2429ec5 commit 1105551
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 70 deletions.
38 changes: 19 additions & 19 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1808,52 +1808,52 @@ Style
-----
.. currentmodule:: pandas.formats.style

``Styler`` objects are returned by :attr:`pandas.DataFrame.style`.
``HTMLStyler`` objects are returned by :attr:`pandas.DataFrame.style`.


Constructor
~~~~~~~~~~~
.. autosummary::
:toctree: generated/

Styler
HTMLStyler

Style Application
~~~~~~~~~~~~~~~~~
.. autosummary::
:toctree: generated/

Styler.apply
Styler.applymap
Styler.format
Styler.set_precision
Styler.set_table_styles
Styler.set_caption
Styler.set_properties
Styler.set_uuid
Styler.clear
HTMLStyler.apply
HTMLStyler.applymap
HTMLStyler.format
HTMLStyler.set_precision
HTMLStyler.set_table_styles
HTMLStyler.set_caption
HTMLStyler.set_properties
HTMLStyler.set_uuid
HTMLStyler.clear

Builtin Styles
~~~~~~~~~~~~~~

.. autosummary::
:toctree: generated/

Styler.highlight_max
Styler.highlight_min
Styler.highlight_null
Styler.background_gradient
Styler.bar
HTMLStyler.highlight_max
HTMLStyler.highlight_min
HTMLStyler.highlight_null
HTMLStyler.background_gradient
HTMLStyler.bar

Style Export and Import
~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
:toctree: generated/

Styler.render
Styler.export
Styler.use
HTMLStyler.render
HTMLStyler.export
HTMLStyler.use

.. currentmodule:: pandas

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ def style(self):
--------
pandas.formats.style.Styler
"""
from pandas.formats.style import Styler
return Styler(self)
from pandas.formats.style import HTMLStyler
return HTMLStyler(self)

def iteritems(self):
"""
Expand Down
72 changes: 36 additions & 36 deletions pandas/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
try:
from jinja2 import Template
except ImportError:
msg = "pandas.Styler requires jinja2. "\
msg = "pandas.HTMLStyler requires jinja2. "\
"Please install with `conda install Jinja2`\n"\
"or `pip install Jinja2`"
raise ImportError(msg)
Expand All @@ -39,7 +39,7 @@ def _mpl(func):
raise ImportError(no_mpl_message.format(func.__name__))


class Styler(object):
class HTMLStyler(object):
"""
Helps style a DataFrame or Series according to the
data with HTML and CSS.
Expand Down Expand Up @@ -70,12 +70,12 @@ class Styler(object):
Notes
-----
Most styling will be done by passing style functions into
``Styler.apply`` or ``Styler.applymap``. Style functions should
``HTMLStyler.apply`` or ``Styler.applymap``. Style functions should
return values with strings containing CSS ``'attr: value'`` that will
be applied to the indicated cells.
If using in the Jupyter notebook, Styler has defined a ``_repr_html_``
to automatically render itself. Otherwise call Styler.render to get
If using in the Jupyter notebook, HTMLStyler has defined a ``_repr_html_``
to automatically render itself. Otherwise call HTMLStyler.render to get
the genterated HTML.
See Also
Expand Down Expand Up @@ -286,7 +286,7 @@ def format(self, formatter, subset=None):
Returns
-------
self : Styler
self : HTMLStyler
Notes
-----
Expand Down Expand Up @@ -349,9 +349,9 @@ def render(self):
Notes
-----
``Styler`` objects have defined the ``_repr_html_`` method
``HTMLStyler`` objects have defined the ``_repr_html_`` method
which automatically calls ``self.render()`` when it's the
last item in a Notebook cell. When calling ``Styler.render()``
last item in a Notebook cell. When calling ``HTMLStyler.render()``
directly, wrap the result in ``IPython.display.HTML`` to view
the rendered HTML in the notebook.
"""
Expand All @@ -367,7 +367,7 @@ def render(self):

def _update_ctx(self, attrs):
"""
update the state of the Styler. Collects a mapping
update the state of the HTMLStyler. Collects a mapping
of {index_label: ['<property>: <value>']}
attrs: Series or DataFrame
Expand All @@ -383,9 +383,9 @@ def _update_ctx(self, attrs):
self.ctx[(i, j)].append(pair)

def _copy(self, deepcopy=False):
styler = Styler(self.data, precision=self.precision,
caption=self.caption, uuid=self.uuid,
table_styles=self.table_styles)
styler = HTMLStyler(self.data, precision=self.precision,
caption=self.caption, uuid=self.uuid,
table_styles=self.table_styles)
if deepcopy:
styler.ctx = copy.deepcopy(self.ctx)
styler._todo = copy.deepcopy(self._todo)
Expand Down Expand Up @@ -457,7 +457,7 @@ def apply(self, func, axis=0, subset=None, **kwargs):
Returns
-------
self : Styler
self : HTMLStyler
Notes
-----
Expand Down Expand Up @@ -496,7 +496,7 @@ def applymap(self, func, subset=None, **kwargs):
Returns
-------
self : Styler
self : HTMLStyler
"""
self._todo.append((lambda instance: getattr(instance, '_applymap'),
Expand All @@ -515,7 +515,7 @@ def set_precision(self, precision):
Returns
-------
self : Styler
self : HTMLStyler
"""
self.precision = precision
return self
Expand All @@ -534,15 +534,15 @@ def set_table_attributes(self, attributes):
Returns
-------
self : Styler
self : HTMLStyler
"""
self.table_attributes = attributes
return self

def export(self):
"""
Export the styles to applied to the current Styler.
Can be applied to a second style with ``Styler.use``.
Export the styles to applied to the current HTMLStyler.
Can be applied to a second style with ``HTMLStyler.use``.
.. versionadded:: 0.17.1
Expand All @@ -552,14 +552,14 @@ def export(self):
See Also
--------
Styler.use
HTMLStyler.use
"""
return self._todo

def use(self, styles):
"""
Set the styles on the current Styler, possibly using styles
from ``Styler.export``.
Set the styles on the current HTMLStyler, possibly using styles
from ``HTMLStyler.export``.
.. versionadded:: 0.17.1
Expand All @@ -570,18 +570,18 @@ def use(self, styles):
Returns
-------
self : Styler
self : HTMLStyler
See Also
--------
Styler.export
HTMLStyler.export
"""
self._todo.extend(styles)
return self

def set_uuid(self, uuid):
"""
Set the uuid for a Styler.
Set the uuid for a HTMLStyler.
.. versionadded:: 0.17.1
Expand All @@ -591,14 +591,14 @@ def set_uuid(self, uuid):
Returns
-------
self : Styler
self : HTMLStyler
"""
self.uuid = uuid
return self

def set_caption(self, caption):
"""
Se the caption on a Styler
Se the caption on a HTMLStyler
.. versionadded:: 0.17.1
Expand All @@ -608,14 +608,14 @@ def set_caption(self, caption):
Returns
-------
self : Styler
self : HTMLStyler
"""
self.caption = caption
return self

def set_table_styles(self, table_styles):
"""
Set the table styles on a Styler. These are placed in a
Set the table styles on a HTMLStyler. These are placed in a
``<style>`` tag before the generated HTML table.
.. versionadded:: 0.17.1
Expand All @@ -631,7 +631,7 @@ def set_table_styles(self, table_styles):
Returns
-------
self : Styler
self : HTMLStyler
Examples
--------
Expand Down Expand Up @@ -664,7 +664,7 @@ def highlight_null(self, null_color='red'):
Returns
-------
self : Styler
self : HTMLStyler
"""
self.applymap(self._highlight_null, null_color=null_color)
return self
Expand All @@ -691,7 +691,7 @@ def background_gradient(self, cmap='PuBu', low=0, high=0, axis=0,
Returns
-------
self : Styler
self : HTMLStyler
Notes
-----
Expand All @@ -709,7 +709,7 @@ def background_gradient(self, cmap='PuBu', low=0, high=0, axis=0,
@staticmethod
def _background_gradient(s, cmap='PuBu', low=0, high=0):
"""Color background in a range according to the data."""
with _mpl(Styler.background_gradient) as (plt, colors):
with _mpl(HTMLStyler.background_gradient) as (plt, colors):
rng = s.max() - s.min()
# extend lower / upper bounds, compresses color range
norm = colors.Normalize(s.min() - (rng * low),
Expand All @@ -736,7 +736,7 @@ def set_properties(self, subset=None, **kwargs):
Returns
-------
self : Styler
self : HTMLStyler
Examples
--------
Expand Down Expand Up @@ -776,7 +776,7 @@ def bar(self, subset=None, axis=0, color='#d65f5f', width=100):
Returns
-------
self : Styler
self : HTMLStyler
"""
subset = _maybe_numeric_slice(self.data, subset)
subset = _non_reducing_slice(subset)
Expand All @@ -801,7 +801,7 @@ def highlight_max(self, subset=None, color='yellow', axis=0):
Returns
-------
self : Styler
self : HTMLStyler
"""
return self._highlight_handler(subset=subset, color=color, axis=axis,
max_=True)
Expand All @@ -823,7 +823,7 @@ def highlight_min(self, subset=None, color='yellow', axis=0):
Returns
-------
self : Styler
self : HTMLStyler
"""
return self._highlight_handler(subset=subset, color=color, axis=axis,
max_=False)
Expand Down
Loading

0 comments on commit 1105551

Please sign in to comment.