-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from posit-dev/feat-style-from-column
feat: add style.from_column, implement for loc.body
Showing
8 changed files
with
259 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,7 @@ quartodoc: | |
contents: | ||
- md | ||
- html | ||
- from_column | ||
#- px | ||
#- pct | ||
- title: Value formatting functions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# serializer version: 1 | ||
# name: test_set_style_loc_title_from_column_error | ||
''' | ||
Location type <class 'great_tables._locations.LocTitle'> cannot use FromColumn. | ||
|
||
Style type: <class 'great_tables._styles.CellStyleText'> | ||
Field with FromColumn: color | ||
''' | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pandas as pd | ||
|
||
from great_tables._styles import FromColumn, CellStyleText | ||
|
||
|
||
def test_from_column_replace(): | ||
"""FromColumn is replaced by the specified column's value in a row of data""" | ||
|
||
df = pd.DataFrame({"x": [1, 2], "color": ["red", "blue"]}) | ||
from_col = FromColumn("color") | ||
|
||
style = CellStyleText(color=from_col) | ||
new_style = style._from_row(df, 0) | ||
|
||
assert style.color is from_col | ||
assert new_style.color == "red" | ||
|
||
|
||
def test_from_column_fn(): | ||
df = pd.DataFrame({"x": [1, 2], "color": ["red", "blue"]}) | ||
from_col = FromColumn("color", fn=lambda x: x.upper()) | ||
|
||
style = CellStyleText(color=from_col) | ||
new_style = style._from_row(df, 0) | ||
|
||
assert new_style.color == "RED" |