@@ -893,8 +893,8 @@ def opt_all_caps(
893
893
894
894
locations
895
895
Which locations should undergo this text transformation? By default it includes all of
896
- the `" column_labels" `, the `" stub"`, and the `" row_group" ` locations. However, we could
897
- just choose one or two of those.
896
+ the `loc. column_labels`, the `loc. stub"`, and the `loc. row_group` locations. However, we
897
+ could just choose one or two of those.
898
898
899
899
Returns
900
900
-------
@@ -909,7 +909,7 @@ def opt_all_caps(
909
909
in all row groups is transformed to all caps using the `opt_all_caps()` method.
910
910
911
911
```{python}
912
- from great_tables import GT, exibble, md
912
+ from great_tables import GT, exibble, loc, md
913
913
914
914
(
915
915
GT(
@@ -927,16 +927,46 @@ def opt_all_caps(
927
927
.opt_all_caps()
928
928
)
929
929
```
930
+ `opt_all_caps()` accepts a `locations` parameter that allows us to specify which components
931
+ should be transformed. For example, if we only want to ensure that all text in the stub and all
932
+ row groups is converted to all caps:
933
+ ```{python}
934
+ (
935
+ GT(
936
+ exibble[["num", "char", "currency", "row", "group"]],
937
+ rowname_col="row",
938
+ groupname_col="group"
939
+ )
940
+ .tab_header(
941
+ title=md("Data listing from **exibble**"),
942
+ subtitle=md("`exibble` is a **Great Tables** dataset.")
943
+ )
944
+ .fmt_number(columns="num")
945
+ .fmt_currency(columns="currency")
946
+ .tab_source_note(source_note="This is only a subset of the dataset.")
947
+ .opt_all_caps(locations=[loc.stub, loc.row_group])
948
+ )
949
+ ```
930
950
"""
951
+ from great_tables ._locations import Loc , LocColumnLabels , LocStub , LocRowGroups
931
952
932
- # If providing a scalar string value, normalize it to be in a list
933
- if not isinstance (locations , list ):
934
- locations = _utils ._str_scalar_to_list (cast (str , locations ))
935
-
936
- # Ensure that the `locations` value is a list of strings
937
- _utils ._assert_str_list (locations )
953
+ if not locations :
954
+ locations = [LocColumnLabels , LocStub , LocRowGroups ]
938
955
939
- # TODO: Ensure that all values within `locations` are valid
956
+ # If providing a Loc object, normalize it to be in a list
957
+ if not isinstance (locations , list ):
958
+ locations = [locations ]
959
+
960
+ # Ensure that all values within `locations` are valid
961
+ # A `try-except` block is needed here because the first argument of `issubclass()` must be a
962
+ # class.
963
+ for location in locations :
964
+ try :
965
+ issubclass (location , Loc )
966
+ except TypeError :
967
+ raise AssertionError (
968
+ f"Only `loc.column_labels`, `loc.stub` and `loc.row_group` are allowed in the locations."
969
+ )
940
970
941
971
# if `all_caps` is False, reset options to default, or, set new options
942
972
# for `locations` selected
@@ -956,23 +986,23 @@ def opt_all_caps(
956
986
957
987
info = [
958
988
(
959
- "column_labels" ,
989
+ LocColumnLabels ,
960
990
{
961
991
"column_labels_font_size" : "80%" ,
962
992
"column_labels_font_weight" : "bolder" ,
963
993
"column_labels_text_transform" : "uppercase" ,
964
994
},
965
995
),
966
996
(
967
- "stub" ,
997
+ LocStub ,
968
998
{
969
999
"stub_font_size" : "80%" ,
970
1000
"stub_font_weight" : "bolder" ,
971
1001
"stub_text_transform" : "uppercase" ,
972
1002
},
973
1003
),
974
1004
(
975
- "row_group" ,
1005
+ LocRowGroups ,
976
1006
{
977
1007
"row_group_font_size" : "80%" ,
978
1008
"row_group_font_weight" : "bolder" ,
0 commit comments