Skip to content

Commit

Permalink
SNOW-1722639: Add support for DataFrame.style (#2503)
Browse files Browse the repository at this point in the history
<!---
Please answer these questions before creating your pull request. Thanks!
--->

1. Which Jira issue is this PR addressing? Make sure that there is an
accompanying issue to your PR.

   <!---
   In this section, please add a Snowflake Jira issue number.

Note that if a corresponding GitHub issue exists, you should still
include
   the Snowflake Jira issue number. For example, for GitHub issue
#1400, you should
   add "SNOW-1335071" here.
    --->

   Fixes SNOW-1722639

2. Fill out the following pre-review checklist:

- [ ] I am adding a new automated test(s) to verify correctness of my
new code
- [ ] If this test skips Local Testing mode, I'm requesting review from
@snowflakedb/local-testing
   - [ ] I am adding new logging messages
   - [ ] I am adding a new telemetry message
   - [ ] I am adding new credentials
   - [ ] I am adding a new dependency
- [ ] If this is a new feature/behavior, I'm adding the Local Testing
parity changes.
- [ ] I acknowledge that I have ensured my changes to be thread-safe.
Follow the link for more information: [Thread-safe Developer
Guidelines](https://docs.google.com/document/d/162d_i4zZ2AfcGRXojj0jByt8EUq-DrSHPPnTa4QvwbA/edit#bookmark=id.e82u4nekq80k)

3. Please describe how your code solves the related issue.

   Add support for DataFrame.style.
  • Loading branch information
sfc-gh-helmeleegy authored Oct 25, 2024
1 parent 9670b1f commit 8383698
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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 | Performed locally on the client |
+-----------------------------+---------------------------------+----------------------------------------------------+
| ``values`` | Y | |
+-----------------------------+---------------------------------+----------------------------------------------------+
Expand Down
21 changes: 20 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,26 @@ def attrs():

@property
def style():
pass
"""
Returns a Styler object.
Contains methods for building a styled HTML representation of the DataFrame.
Snowpark pandas uses native pandas for this functionality.
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.to_string()
' A\\n0 1\\n1 2\\n2 3\\n'
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 8383698

Please sign in to comment.