Skip to content

Commit

Permalink
SNOW-1722639: Add support for DataFrame.style
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-helmeleegy committed Oct 24, 2024
1 parent 0409865 commit c0779ca
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
- Added support for `on` parameter with `Resampler`.
- Added support for timedelta inputs in `value_counts()`.
- Added support for applying Snowpark Python function `snowflake_cortex_summarize`.
- Added support for `DataFrame`/`Series.attrs`
- Added support for `DataFrame.attrs` and `Series.attrs`.
- Added support for `DataFrame.style`.

#### Improvements

Expand Down
2 changes: 1 addition & 1 deletion docs/source/modin/supported/dataframe_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Attributes
+-----------------------------+---------------------------------+----------------------------------------------------+
| ``size`` | Y | |
+-----------------------------+---------------------------------+----------------------------------------------------+
| ``style`` | N | |
| ``style`` | Y | |
+-----------------------------+---------------------------------+----------------------------------------------------+
| ``values`` | Y | |
+-----------------------------+---------------------------------+----------------------------------------------------+
Expand Down
18 changes: 17 additions & 1 deletion src/snowflake/snowpark/modin/plugin/docstrings/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5125,7 +5125,23 @@ def attrs():

@property
def style():
pass
"""
Returns a Styler object.
Contains methods for building a styled HTML representation of the DataFrame.
See Also
--------
io.formats.style.Styler
Helps style a DataFrame or Series according to the data with HTML and CSS.
Examples
--------
>>> df = pd.DataFrame({'A': [1, 2, 3]})
>>> df.style
Please see `Table Visualization <https://pandas.pydata.org/docs/user_guide/style.html>`_ for more examples.
"""

def isin():
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,9 @@ def __delitem__(self, key):


@register_dataframe_accessor("style")
@dataframe_not_implemented()
@property
def style(self): # noqa: RT01, D200
pass # pragma: no cover
return self._to_pandas().style


@register_dataframe_not_implemented()
Expand Down
24 changes: 24 additions & 0 deletions tests/integ/modin/frame/test_style.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
#

import modin.pandas as pd
import pandas as npd

from tests.integ.utils.sql_counter import sql_count_checker

species = ["adelie"] * 3 + ["chinstrap"] * 3 + ["gentoo"] * 3
measurements = ["bill_length", "flipper_length", "bill_depth"] * 3
values = [37.3, 187.1, 17.7, 46.6, 191.7, 17.6, 45.5, 212.7, 14.2]


@sql_count_checker(query_count=1, join_count=0)
def test_simple_style_accessor():
ndf = npd.DataFrame(
{"species": species, "measurement": measurements, "value": values}
)
df = pd.DataFrame(
{"species": species, "measurement": measurements, "value": values}
)

assert df.style.to_string() == ndf.style.to_string()
1 change: 0 additions & 1 deletion tests/unit/modin/test_unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def test_unsupported_general(general_method, kwargs):
["reorder_levels", {"order": ""}],
["sem", {}],
["set_flags", {}],
["style", {}],
["swapaxes", {"axis1": "", "axis2": ""}],
["swaplevel", {}],
["to_clipboard", {}],
Expand Down

0 comments on commit c0779ca

Please sign in to comment.