Skip to content

Commit 5f37a77

Browse files
authored
Merging devel to master - 2.0.5 (#59)
- `style_alternate_rows` can accept all arguments that `apply_style_by_indexes` accepts as kwargs. - Added `cols_to_style` argument to `apply_headers_style` - Changed required version of xlrd to >= 1.0.0
1 parent 9721534 commit 5f37a77

7 files changed

Lines changed: 413 additions & 415 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#### 2.0.5
2+
* `style_alternate_rows` can accept all arguments that `apply_style_by_indexes` accepts as kwargs.
3+
* Added `cols_to_style` argument to `apply_headers_style`
4+
15
#### 2.0.4
26
* Fixed a bug that caused `apply_style_by_indexes` not to work in case the dataframe had non-integer indexes in some cases
37
* Added support for text rotation

StyleFrame/style_frame.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,23 +556,30 @@ def apply_column_style(self, cols_to_style, styler_obj, style_header=False, use_
556556

557557
return self
558558

559-
def apply_headers_style(self, styler_obj, style_index_header=True):
559+
def apply_headers_style(self, styler_obj, style_index_header=True, cols_to_style=None):
560560
"""Apply style to the headers only
561-
562561
:param Styler styler_obj: the styler object that contains the style to be applied
563562
:param bool style_index_header: if True then the style will also be applied to the header of the index column
563+
:param None|str|list|tuple|set cols_to_style: the columns to apply the style to, if not provided all the columns will be styled
564564
:return: self
565565
:rtype: StyleFrame
566566
"""
567567

568568
if not isinstance(styler_obj, Styler):
569569
raise TypeError('styler_obj must be {}, got {} instead.'.format(Styler.__name__, type(styler_obj).__name__))
570570

571+
if cols_to_style is None:
572+
cols_to_style = self.data_df.columns
573+
if not isinstance(cols_to_style, (list, tuple, set, pd.Index)):
574+
cols_to_style = [cols_to_style]
575+
if not all(col in self.columns for col in cols_to_style):
576+
raise KeyError("one of the columns in {} wasn't found".format(cols_to_style))
577+
571578
if style_index_header:
572579
self._index_header_style = styler_obj
573580

574-
for column in self.data_df.columns:
575-
column.style = styler_obj
581+
for column in cols_to_style:
582+
self.columns[self.columns.get_loc(column)].style = styler_obj
576583
self._has_custom_headers_style = True
577584
return self
578585

@@ -680,7 +687,7 @@ def rename(self, columns=None, inplace=False):
680687
if old_col_name in sf._columns_width})
681688
return sf
682689

683-
def style_alternate_rows(self, styles):
690+
def style_alternate_rows(self, styles, **kwargs):
684691
"""Applies the provided styles to rows in an alternating manner.
685692
686693
:param list|tuple|set styles: styles to apply
@@ -690,7 +697,7 @@ def style_alternate_rows(self, styles):
690697
num_of_styles = len(styles)
691698
split_indexes = (self.index[i::num_of_styles] for i in range(num_of_styles))
692699
for i, indexes in enumerate(split_indexes):
693-
self.apply_style_by_indexes(indexes, styles[i])
700+
self.apply_style_by_indexes(indexes, styles[i], **kwargs)
694701
return self
695702

696703
def add_color_scale_conditional_formatting(self, start_type, start_value, start_color, end_type, end_value, end_color,

StyleFrame/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_all_versions():
1717
return _versions_
1818

1919

20-
_version_ = '2.0.4'
20+
_version_ = '2.0.5'
2121
_python_version_ = get_python_version()
2222
_pandas_version_ = get_pandas_version()
2323
_openpyxl_version_ = get_openpyxl_version()

0 commit comments

Comments
 (0)