Skip to content

Commit b906173

Browse files
committed
fix ; rename cols -> columns
1 parent 806ef8c commit b906173

File tree

2 files changed

+66
-66
lines changed

2 files changed

+66
-66
lines changed

pandas/io/formats/style.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Styler(object):
7575
7676
.. versionadded:: 0.20.2
7777
78-
hidden_cols: IndexSlice, default None
78+
hidden_columns: IndexSlice, default None
7979
hides a subset of columns from rendering
8080
8181
.. versionadded:: 0.20.2
@@ -128,7 +128,7 @@ class Styler(object):
128128

129129
def __init__(self, data, precision=None, table_styles=None, uuid=None,
130130
caption=None, table_attributes=None, index=True,
131-
hidden_cols=None):
131+
hidden_columns=None):
132132
self.ctx = defaultdict(list)
133133
self._todo = []
134134

@@ -151,9 +151,9 @@ def __init__(self, data, precision=None, table_styles=None, uuid=None,
151151
self.precision = precision
152152
self.table_attributes = table_attributes
153153
self.index_visible = index
154-
if hidden_cols is None:
155-
hidden_cols = []
156-
self.hidden_cols = hidden_cols
154+
if hidden_columns is None:
155+
hidden_columns = []
156+
self.hidden_columns = hidden_columns
157157

158158
# display_funcs maps (row, col) -> formatting function
159159

@@ -203,7 +203,7 @@ def _translate(self):
203203
ctx = self.ctx
204204
precision = self.precision
205205
index_visible = self.index_visible
206-
hidden_cols = self.hidden_cols
206+
hidden_columns = self.hidden_columns
207207
uuid = self.uuid or str(uuid1()).replace("-", "_")
208208
ROW_HEADING_CLASS = "row_heading"
209209
COL_HEADING_CLASS = "col_heading"
@@ -218,7 +218,7 @@ def format_attr(pair):
218218

219219
# for sparsifying a MultiIndex
220220
idx_lengths = _get_level_lengths(self.index)
221-
col_lengths = _get_level_lengths(self.columns, hidden_cols)
221+
col_lengths = _get_level_lengths(self.columns, hidden_columns)
222222

223223
cell_context = dict()
224224

@@ -289,7 +289,7 @@ def format_attr(pair):
289289
[{"type": "th",
290290
"value": BLANK_VALUE,
291291
"class": " ".join([BLANK_CLASS])
292-
}] * (len(clabels[0]) - len(hidden_cols)))
292+
}] * (len(clabels[0]) - len(hidden_columns)))
293293

294294
head.append(index_header_row)
295295

@@ -324,7 +324,7 @@ def format_attr(pair):
324324
"class": " ".join(cs),
325325
"id": "_".join(cs[1:]),
326326
"display_value": formatter(value),
327-
"is_visible": (c not in hidden_cols)
327+
"is_visible": (c not in hidden_columns)
328328
})
329329
props = []
330330
for x in ctx[r, c]:
@@ -482,7 +482,7 @@ def _copy(self, deepcopy=False):
482482
caption=self.caption, uuid=self.uuid,
483483
table_styles=self.table_styles,
484484
index=self.index_visible,
485-
hidden_cols=self.hidden_cols)
485+
hidden_columns=self.hidden_columns)
486486
if deepcopy:
487487
styler.ctx = copy.deepcopy(self.ctx)
488488
styler._todo = copy.deepcopy(self._todo)
@@ -816,7 +816,7 @@ def hide_columns(self, subset):
816816
"""
817817
subset = _non_reducing_slice(subset)
818818
hidden_df = self.data.loc[subset]
819-
self.hidden_cols = self.columns.get_indexer_for(hidden_df.columns)
819+
self.hidden_columns = self.columns.get_indexer_for(hidden_df.columns)
820820
return self
821821

822822
# -----------------------------------------------------------------------

pandas/tests/io/formats/test_style.py

+55-55
Original file line numberDiff line numberDiff line change
@@ -814,22 +814,22 @@ def test_mi_sparse_column_names(self):
814814
def test_hide_single_index(self):
815815
# single unnamed index
816816
ctx = self.df.style._translate()
817-
assert(ctx['body'][0][0]['is_visible'])
818-
assert(ctx['head'][0][0]['is_visible'])
817+
assert ctx['body'][0][0]['is_visible']
818+
assert ctx['head'][0][0]['is_visible']
819819
ctx2 = self.df.style.hide_index()._translate()
820-
assert(not ctx2['body'][0][0]['is_visible'])
821-
assert(not ctx2['head'][0][0]['is_visible'])
820+
assert not ctx2['body'][0][0]['is_visible']
821+
assert not ctx2['head'][0][0]['is_visible']
822822

823823
# single named index
824824
ctx3 = self.df.set_index('A').style._translate()
825-
assert(ctx3['body'][0][0]['is_visible'])
826-
assert(len(ctx3['head']) == 2) # 2 header levels
827-
assert(ctx3['head'][0][0]['is_visible'])
825+
assert ctx3['body'][0][0]['is_visible']
826+
assert len(ctx3['head']) == 2 # 2 header levels
827+
assert ctx3['head'][0][0]['is_visible']
828828

829829
ctx4 = self.df.set_index('A').style.hide_index()._translate()
830-
assert(not ctx4['body'][0][0]['is_visible'])
831-
assert(len(ctx4['head']) == 1) # only 1 header levels
832-
assert(not ctx4['head'][0][0]['is_visible'])
830+
assert not ctx4['body'][0][0]['is_visible']
831+
assert len(ctx4['head']) == 1 # only 1 header levels
832+
assert not ctx4['head'][0][0]['is_visible']
833833

834834
def test_hide_multiindex(self):
835835
df = pd.DataFrame({'A': [1, 2]}, index=pd.MultiIndex.from_arrays(
@@ -838,41 +838,41 @@ def test_hide_multiindex(self):
838838
)
839839
ctx1 = df.style._translate()
840840
# tests for 'a' and '0'
841-
assert(ctx1['body'][0][0]['is_visible'])
842-
assert(ctx1['body'][0][1]['is_visible'])
841+
assert ctx1['body'][0][0]['is_visible']
842+
assert ctx1['body'][0][1]['is_visible']
843843
# check for blank header rows
844-
assert(ctx1['head'][0][0]['is_visible'])
845-
assert(ctx1['head'][0][1]['is_visible'])
844+
assert ctx1['head'][0][0]['is_visible']
845+
assert ctx1['head'][0][1]['is_visible']
846846

847847
ctx2 = df.style.hide_index()._translate()
848848
# tests for 'a' and '0'
849-
assert(not ctx2['body'][0][0]['is_visible'])
850-
assert(not ctx2['body'][0][1]['is_visible'])
849+
assert not ctx2['body'][0][0]['is_visible']
850+
assert not ctx2['body'][0][1]['is_visible']
851851
# check for blank header rows
852-
assert(not ctx2['head'][0][0]['is_visible'])
853-
assert(not ctx2['head'][0][1]['is_visible'])
852+
assert not ctx2['head'][0][0]['is_visible']
853+
assert not ctx2['head'][0][1]['is_visible']
854854

855855
def test_hide_columns_single_level(self):
856856
# test hiding single column
857857
ctx = self.df.style._translate()
858-
assert(ctx['head'][0][1]['is_visible'])
859-
assert(ctx['head'][0][1]['display_value'] == 'A')
860-
assert(ctx['head'][0][2]['is_visible'])
861-
assert(ctx['head'][0][2]['display_value'] == 'B')
862-
assert(ctx['body'][0][1]['is_visible']) # col A, row 1
863-
assert(ctx['body'][1][2]['is_visible']) # col B, row 1
858+
assert ctx['head'][0][1]['is_visible']
859+
assert ctx['head'][0][1]['display_value'] == 'A'
860+
assert ctx['head'][0][2]['is_visible']
861+
assert ctx['head'][0][2]['display_value'] == 'B'
862+
assert ctx['body'][0][1]['is_visible'] # col A, row 1
863+
assert ctx['body'][1][2]['is_visible'] # col B, row 1
864864

865865
ctx = self.df.style.hide_columns('A')._translate()
866-
assert(not ctx['head'][0][1]['is_visible'])
867-
assert(not ctx['body'][0][1]['is_visible']) # col A, row 1
868-
assert(ctx['body'][1][2]['is_visible']) # col B, row 1
866+
assert not ctx['head'][0][1]['is_visible']
867+
assert not ctx['body'][0][1]['is_visible'] # col A, row 1
868+
assert ctx['body'][1][2]['is_visible'] # col B, row 1
869869

870870
# test hiding mulitiple columns
871871
ctx = self.df.style.hide_columns(['A', 'B'])._translate()
872-
assert(not ctx['head'][0][1]['is_visible'])
873-
assert(not ctx['head'][0][2]['is_visible'])
874-
assert(not ctx['body'][0][1]['is_visible']) # col A, row 1
875-
assert(not ctx['body'][1][2]['is_visible']) # col B, row 1
872+
assert not ctx['head'][0][1]['is_visible']
873+
assert not ctx['head'][0][2]['is_visible']
874+
assert not ctx['body'][0][1]['is_visible'] # col A, row 1
875+
assert not ctx['body'][1][2]['is_visible'] # col B, row 1
876876

877877
def test_hide_columns_mult_levels(self):
878878
# setup dataframe with multiple column levels and indices
@@ -885,41 +885,41 @@ def test_hide_columns_mult_levels(self):
885885
df = pd.DataFrame([[1, 2], [3, 4]], index=i1, columns=i2)
886886
ctx = df.style._translate()
887887
# column headers
888-
assert(ctx['head'][0][2]['is_visible'])
889-
assert(ctx['head'][1][2]['is_visible'])
890-
assert(ctx['head'][1][3]['display_value'] == 1)
888+
assert ctx['head'][0][2]['is_visible']
889+
assert ctx['head'][1][2]['is_visible']
890+
assert ctx['head'][1][3]['display_value'] == 1
891891
# indices
892-
assert(ctx['body'][0][0]['is_visible'])
892+
assert ctx['body'][0][0]['is_visible']
893893
# data
894-
assert(ctx['body'][1][2]['is_visible'])
895-
assert(ctx['body'][1][2]['display_value'] == 3)
896-
assert(ctx['body'][1][3]['is_visible'])
897-
assert(ctx['body'][1][3]['display_value'] == 4)
894+
assert ctx['body'][1][2]['is_visible']
895+
assert ctx['body'][1][2]['display_value'] == 3
896+
assert ctx['body'][1][3]['is_visible']
897+
assert ctx['body'][1][3]['display_value'] == 4
898898

899899
# hide top column level, which hides both columns
900900
ctx = df.style.hide_columns('b')._translate()
901-
assert(not ctx['head'][0][2]['is_visible']) # b
902-
assert(not ctx['head'][1][2]['is_visible']) # 0
903-
assert(not ctx['body'][1][2]['is_visible']) # 3
904-
assert(ctx['body'][0][0]['is_visible']) # index
901+
assert not ctx['head'][0][2]['is_visible'] # b
902+
assert not ctx['head'][1][2]['is_visible'] # 0
903+
assert not ctx['body'][1][2]['is_visible'] # 3
904+
assert ctx['body'][0][0]['is_visible'] # index
905905

906906
# hide first column only
907907
ctx = df.style.hide_columns([('b', 0)])._translate()
908-
assert(ctx['head'][0][2]['is_visible']) # b
909-
assert(not ctx['head'][1][2]['is_visible']) # 0
910-
assert(not ctx['body'][1][2]['is_visible']) # 3
911-
assert(ctx['body'][1][3]['is_visible'])
912-
assert(ctx['body'][1][3]['display_value'] == 4)
908+
assert ctx['head'][0][2]['is_visible'] # b
909+
assert not ctx['head'][1][2]['is_visible'] # 0
910+
assert not ctx['body'][1][2]['is_visible'] # 3
911+
assert ctx['body'][1][3]['is_visible']
912+
assert ctx['body'][1][3]['display_value'] == 4
913913

914914
# hide second column and index
915915
ctx = df.style.hide_columns([('b', 1)]).hide_index()._translate()
916-
assert(not ctx['body'][0][0]['is_visible']) # index
917-
assert(ctx['head'][0][2]['is_visible']) # b
918-
assert(ctx['head'][1][2]['is_visible']) # 0
919-
assert(not ctx['head'][1][3]['is_visible']) # 1
920-
assert(not ctx['body'][1][3]['is_visible']) # 4
921-
assert(ctx['body'][1][2]['is_visible'])
922-
assert(ctx['body'][1][2]['display_value'] == 3)
916+
assert not ctx['body'][0][0]['is_visible'] # index
917+
assert ctx['head'][0][2]['is_visible'] # b
918+
assert ctx['head'][1][2]['is_visible'] # 0
919+
assert not ctx['head'][1][3]['is_visible'] # 1
920+
assert not ctx['body'][1][3]['is_visible'] # 4
921+
assert ctx['body'][1][2]['is_visible']
922+
assert ctx['body'][1][2]['display_value'] == 3
923923

924924

925925
class TestStylerMatplotlibDep(object):

0 commit comments

Comments
 (0)