Skip to content

Commit

Permalink
chore: use GTSelf for cols_ funcs, add cols_hide test
Browse files Browse the repository at this point in the history
  • Loading branch information
machow committed Dec 14, 2023
1 parent cae8dd9 commit 3de5f14
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions great_tables/_spanners.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ._locations import SelectExpr, resolve_cols_c

if TYPE_CHECKING:
from ._gt_data import GTData, Boxhead
from ._gt_data import Boxhead
from ._types import GTSelf


Expand Down Expand Up @@ -188,7 +188,7 @@ def tab_spanner(
return new_data


def cols_move(data: GTData, columns: SelectExpr, after: str) -> GTData:
def cols_move(data: GTSelf, columns: SelectExpr, after: str) -> GTSelf:
"""Move one or more columns.
On those occasions where you need to move columns this way or that way, we can make use of the
Expand Down Expand Up @@ -411,7 +411,7 @@ def cols_move_to_end(data: GTSelf, columns: SelectExpr) -> GTSelf:
return data._replace(_boxhead=new_boxhead)


def cols_hide(data: GTData, columns: SelectExpr) -> GTData:
def cols_hide(data: GTSelf, columns: SelectExpr) -> GTSelf:
"""Hide one or more columns.
The `cols_hide()` method allows us to hide one or more columns from appearing in the final
Expand Down
12 changes: 12 additions & 0 deletions tests/test_spanners.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
spanners_print_matrix,
empty_spanner_matrix,
tab_spanner,
cols_hide,
cols_move,
)
from great_tables._gt_data import Spanners, SpannerInfo, Boxhead, ColInfo, ColInfoTypeEnum
Expand Down Expand Up @@ -150,6 +151,17 @@ def test_tab_spanners_with_gather():
assert [col.var for col in new_gt._boxhead] == ["a", "c", "b"]


def test_cols_hide():
df = pd.DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6]})
src_gt = GT(df)

new_gt = cols_hide(src_gt, columns=["a"])
assert [col.var for col in new_gt._boxhead if col.visible] == ["b", "c"]

new_gt = cols_hide(src_gt, columns=["a", "b"])
assert [col.var for col in new_gt._boxhead if col.visible] == ["c"]


def test_cols_move():
df = pd.DataFrame({"a": [1, 2], "b": [3, 4], "c": [5, 6]})
src_gt = GT(df)
Expand Down

0 comments on commit 3de5f14

Please sign in to comment.