-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add style.from_column, implement for loc.body
- Loading branch information
Showing
6 changed files
with
108 additions
and
6 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
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,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" |