Skip to content

Commit 521219f

Browse files
committed
Fixed wrongly raised ValueError when passing border_type=utils.borders.default_grid to Styler - Closes #94
1 parent d331bea commit 521219f

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
#### 3.0.6
2+
* Fixes [GitHub issue #94](https://github.com/DeepSpace2/StyleFrame/issues/94) - Passing `border_type=utils.borders.default_grid` to `Styler`
3+
14
#### 3.0.5
2-
* Fixes github issue #81 - read excel as template headers height
5+
* Fixes [GitHub issue #81](https://github.com/DeepSpace2/StyleFrame/issues/81) - read excel as template headers height
36

47
#### 3.0.4
5-
* Fixed style "shifts" when using `read_style=True` and `header=None` with `StyleFrame.read_excel`. Fixes github issue #80
8+
* Fixed style "shifts" when using `read_style=True` and `header=None` with `StyleFrame.read_excel`. Fixes [GitHub issue #80](https://github.com/DeepSpace2/StyleFrame/issues/80)
69

710
#### 3.0.3
8-
No longer relying on openpyxl's colors definition. Related to github issue #73
11+
No longer relying on openpyxl's colors definition. Related to [GitHub issue #73](https://github.com/DeepSpace2/StyleFrame/issues/73)
912

1013
#### 3.0.2
11-
Hotfix release - setting maximum versions for dependencies. Related to github issue #73
14+
Hotfix release - setting maximum versions for dependencies. Related to [GitHub issue #73](https://github.com/DeepSpace2/StyleFrame/issues/73)
1215

1316
#### 3.0.1
1417
* **Removed Python 2.7 support**
@@ -23,8 +26,8 @@ Hotfix release - setting maximum versions for dependencies. Related to github is
2326

2427
* Added `default_grid` to `utils.borders` to allow usage of the default spreadsheet grid
2528
* Added `read_excel_as_template` method
26-
* Fixed a bug that prevented saving if `read_excel` was used with `use_openpxl_style=True`, see github issue #67
27-
* Allowing usage of pathlib.Path in `to_excel`, see github issue #69
29+
* Fixed a bug that prevented saving if `read_excel` was used with `use_openpxl_style=True`, see [GitHub issue #67](https://github.com/DeepSpace2/StyleFrame/issues/67)
30+
* Allowing usage of pathlib.Path in `to_excel`, see [GitHub issue #69](https://github.com/DeepSpace2/StyleFrame/issues/69)
2831
* Added ability to execute the tests from the commandline: `styleframe --test`
2932

3033
#### 2.0.5
@@ -71,7 +74,7 @@ Hotfix release - setting maximum versions for dependencies. Related to github is
7174

7275
#### 1.5.1
7376
* Fixed a bug where `read_excel` will fail when using `read_style=True` in cases
74-
where specific themes are used (See github issue #37).
77+
where specific themes are used (See [GitHub issue #37](https://github.com/DeepSpace2/StyleFrame/issues/37)).
7578

7679
#### 1.5
7780
* Added `complement_style` and `complement_height` arguments to `StyleFrame.apply_style_by_indexes`
@@ -93,7 +96,7 @@ Hotfix release - setting maximum versions for dependencies. Related to github is
9396

9497
#### 1.3.1
9598
* Improved error message if invalid style arguments are used in JSON through the commandline interface
96-
* Fixed an error importing utils in case there is already a utils module in Python's path (see github issue #31)
99+
* Fixed an error importing utils in case there is already a utils module in Python's path (see [GitHub issue #31](https://github.com/DeepSpace2/StyleFrame/issues/31))
97100

98101
#### 1.3
99102
* Added `utils.fill_pattern_types`

styleframe/styler.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,32 @@ def get_color_from_string(color_str, default_color=None):
6161
color_str = utils.colors.get(color_str, default_color)
6262
return color_str
6363

64+
if border_type == utils.borders.default_grid:
65+
if bg_color is not None or fill_pattern_type != utils.fill_pattern_types.solid:
66+
raise ValueError('`bg_color`or `fill_pattern_type` conflict with border_type={}'.format(utils.borders.default_grid))
67+
self.border_type = None
68+
self.fill_pattern_type = None
69+
else:
70+
self.border_type = border_type
71+
self.fill_pattern_type = fill_pattern_type
72+
6473
self.bold = bold
6574
self.font = font
6675
self.font_size = font_size
6776
self.number_format = number_format
6877
self.protection = protection
6978
self.underline = underline
70-
self.border_type = border_type
7179
self.horizontal_alignment = horizontal_alignment
7280
self.vertical_alignment = vertical_alignment
7381
self.bg_color = get_color_from_string(bg_color, default_color=utils.colors.white)
7482
self.font_color = get_color_from_string(font_color, default_color=utils.colors.black)
7583
self.shrink_to_fit = shrink_to_fit
7684
self.wrap_text = wrap_text
77-
self.fill_pattern_type = fill_pattern_type
7885
self.indent = indent
7986
self.comment_author = comment_author
8087
self.comment_text = comment_text
8188
self.text_rotation = text_rotation
8289

83-
if self.border_type == utils.borders.default_grid:
84-
if self.bg_color is not None:
85-
raise ValueError('bg_color and border_type={} can not be used together'.format(utils.borders.default_grid))
86-
self.border_type = None
87-
self.fill_pattern_type = None
88-
8990
def __eq__(self, other):
9091
if not isinstance(other, self.__class__):
9192
return False

styleframe/tests/styler_tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def test_from_openpyxl_style(self):
3535

3636
self.assertEqual(styler_obj, Styler.from_openpyxl_style(styler_obj.to_openpyxl_style(), []))
3737

38-
def test_default_grid_and_bg_color(self):
38+
def test_default_grid_invalid_args(self):
3939
with self.assertRaises(ValueError):
4040
Styler(border_type=utils.borders.default_grid, bg_color=utils.colors.yellow)
41+
with self.assertRaises(ValueError):
42+
Styler(border_type=utils.borders.default_grid, fill_pattern_type=utils.fill_pattern_types.light_grid)
43+
with self.assertRaises(ValueError):
44+
Styler(border_type=utils.borders.default_grid, bg_color=utils.colors.yellow,
45+
fill_pattern_type=utils.fill_pattern_types.light_grid)
46+

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_ = '3.0.5'
20+
_version_ = '3.0.6'
2121
_python_version_ = get_python_version()
2222
_pandas_version_ = get_pandas_version()
2323
_openpyxl_version_ = get_openpyxl_version()

0 commit comments

Comments
 (0)