@@ -1012,7 +1012,7 @@ def _update_ctx(self, attrs: DataFrame) -> None:
1012
1012
i , j = self .index .get_loc (rn ), self .columns .get_loc (cn )
1013
1013
self .ctx [(i , j )].extend (css_list )
1014
1014
1015
- def _update_ctx_header (self , attrs : DataFrame , axis : str ) -> None :
1015
+ def _update_ctx_header (self , attrs : DataFrame , axis : int ) -> None :
1016
1016
"""
1017
1017
Update the state of the ``Styler`` for header cells.
1018
1018
@@ -1025,15 +1025,15 @@ def _update_ctx_header(self, attrs: DataFrame, axis: str) -> None:
1025
1025
integer index.
1026
1026
Whitespace shouldn't matter and the final trailing ';' shouldn't
1027
1027
matter.
1028
- axis : str
1028
+ axis : int
1029
1029
Identifies whether the ctx object being updated is the index or columns
1030
1030
"""
1031
1031
for j in attrs .columns :
1032
1032
for i , c in attrs [[j ]].itertuples ():
1033
1033
if not c :
1034
1034
continue
1035
1035
css_list = maybe_convert_css_to_tuples (c )
1036
- if axis == "index" :
1036
+ if axis == 0 :
1037
1037
self .ctx_index [(i , j )].extend (css_list )
1038
1038
else :
1039
1039
self .ctx_columns [(j , i )].extend (css_list )
@@ -1253,14 +1253,8 @@ def _apply_index(
1253
1253
method : str = "apply" ,
1254
1254
** kwargs ,
1255
1255
) -> Styler :
1256
- if axis in [0 , "index" ]:
1257
- obj , axis = self .index , "index"
1258
- elif axis in [1 , "columns" ]:
1259
- obj , axis = self .columns , "columns"
1260
- else :
1261
- raise ValueError (
1262
- f"`axis` must be one of 0, 1, 'index', 'columns', got { axis } "
1263
- )
1256
+ axis = self .data ._get_axis_number (axis )
1257
+ obj = self .index if axis == 0 else self .columns
1264
1258
1265
1259
levels_ = _refactor_levels (level , obj )
1266
1260
data = DataFrame (obj .to_list ()).loc [:, levels_ ]
@@ -1709,14 +1703,9 @@ def set_sticky(
1709
1703
1710
1704
may produce strange behaviour due to CSS controls with missing elements.
1711
1705
"""
1712
- if axis in [0 , "index" ]:
1713
- axis , obj = 0 , self .data .index
1714
- pixel_size = 75 if not pixel_size else pixel_size
1715
- elif axis in [1 , "columns" ]:
1716
- axis , obj = 1 , self .data .columns
1717
- pixel_size = 25 if not pixel_size else pixel_size
1718
- else :
1719
- raise ValueError ("`axis` must be one of {0, 1, 'index', 'columns'}" )
1706
+ axis = self .data ._get_axis_number (axis )
1707
+ obj = self .data .index if axis == 0 else self .data .columns
1708
+ pixel_size = (75 if axis == 0 else 25 ) if not pixel_size else pixel_size
1720
1709
1721
1710
props = "position:sticky; background-color:white;"
1722
1711
if not isinstance (obj , pd .MultiIndex ):
@@ -1901,10 +1890,9 @@ def set_table_styles(
1901
1890
more details.
1902
1891
"""
1903
1892
if isinstance (table_styles , dict ):
1904
- if axis in [0 , "index" ]:
1905
- obj , idf = self .data .columns , ".col"
1906
- else :
1907
- obj , idf = self .data .index , ".row"
1893
+ axis = self .data ._get_axis_number (axis )
1894
+ obj = self .data .index if axis == 1 else self .data .columns
1895
+ idf = ".row" if axis == 1 else ".col"
1908
1896
1909
1897
table_styles = [
1910
1898
{
@@ -2869,15 +2857,13 @@ def highlight_quantile(
2869
2857
# after quantile is found along axis, e.g. along rows,
2870
2858
# applying the calculated quantile to alternate axis, e.g. to each column
2871
2859
kwargs = {"q" : [q_left , q_right ], "interpolation" : interpolation }
2872
- if axis in [0 , "index" ]:
2873
- q = data .quantile (axis = axis , numeric_only = False , ** kwargs )
2874
- axis_apply : int | None = 1
2875
- elif axis in [1 , "columns" ]:
2876
- q = data .quantile (axis = axis , numeric_only = False , ** kwargs )
2877
- axis_apply = 0
2878
- else : # axis is None
2860
+ if axis is None :
2879
2861
q = Series (data .to_numpy ().ravel ()).quantile (** kwargs )
2880
- axis_apply = None
2862
+ axis_apply : int | None = None
2863
+ else :
2864
+ axis = self .data ._get_axis_number (axis )
2865
+ q = data .quantile (axis = axis , numeric_only = False , ** kwargs )
2866
+ axis_apply = 1 - axis
2881
2867
2882
2868
if props is None :
2883
2869
props = f"background-color: { color } ;"
0 commit comments