Skip to content

cols_*() methods do not raise if a list of column names not all in data #817

@machow

Description

@machow

The cols_*() methods raise if a single column name is passed that is not in the data. However, they do not raise if that missing name is in a list.

Here's a reprex

# %%
import pandas as pd                                                                                                                                                       
import great_tables as gt                                                                                                                                                 
                                                                                                                                                                          
df = pd.DataFrame({"A": [1], "B": [2]})                                                                                                                                   
t = gt.GT(df)                                                                                                                                                             
                                                                                                                                                                          
# String input → raises error                                                                                                                                             
# t.cols_align(columns="NOPE")           # AssertionError
# t.cols_label_with(columns="NOPE", fn=str.lower)  # AssertionError

# List input → silently ignores "NOPE"
t.cols_align(columns=["A", "NOPE"])              # no error, only A aligned
t.cols_label_with(columns=["A", "NOPE"], fn=str.lower)  # no error, only A relabeled
t.cols_hide(columns=["A", "NOPE"])               # no error, only A hidden
t.cols_move(columns=["A", "NOPE"], after="A")               # no error, only A moved
t.cols_move_to_start(columns=["A", "NOPE"])      # no error
t.cols_move_to_end(columns=["A", "NOPE"])        # no error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions