Skip to content

Commit 26a2b9c

Browse files
authored
Merge pull request #162 from DeepSpace2/devel
4.2 release
2 parents c8a1117 + 2052ed0 commit 26a2b9c

File tree

16 files changed

+300
-146
lines changed

16 files changed

+300
-146
lines changed

.github/CONTRIBUTING.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
1-
Thanks for contributing. If creating a pull request please make sure to submit it to the `devel` branch and not to `master`.
2-
Happy coding!
1+
### Thanks for contributing!
2+
3+
# Branch
4+
Create the pull request against the `devel` branch instead of the `master`.
5+
6+
# Quality
7+
All pull requests are welcome regardless of quality. We will work together to review and improve the pull request.
8+
9+
Of course there are some steps that could be considered to improve the quality of the pull request and to support the process of review and development.
10+
11+
- Make sure your code follows [PEP 8 — Style Guide for Python Code](https://pep8.org/). You can use some [linting tools](https://en.wikipedia.org/wiki/Lint_(software)) to automate the process (e.g. [`pycodestyle`](https://pycodestyle.pycqa.org) or [`flake8`](https://github.com/pycqa/flake8)).
12+
- Test your code using the existing test cases. For details read further.
13+
- It would be great if you could create [`unittest`](https://docs.python.org/3/library/unittest.html)'s for your code.
14+
15+
# Unittesting
16+
17+
This project uses Python's default [`unittest`](https://docs.python.org/3/library/unittest.html) package. You can run all test cases via the *discover* feature when you run this in the projects root folder.
18+
19+
```sh
20+
python3 -m unittest discover
21+
```
22+
23+
The output should look like this
24+
```sh
25+
----------------------------------------------------------------------
26+
Ran 74 tests in 0.823s
27+
28+
OK
29+
```
30+
31+
If you want to run a specific test case or method you need to *install* the package first. It is recommended to use a virtual environment and the `--editable` flag of `pip`. Run this in the projects root folder:
32+
```sh
33+
python3 -m pip install --editable .
34+
```
35+
Please read further to understand the consequences of `--editable`.
36+
- ["pip documentation - Local project installs - Editable installs"](https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs)
37+
- ["When would the -e, --editable option be useful with pip install?"](https://stackoverflow.com/q/35064426/4865723)
38+
39+
### Happy coding!

.github/workflows/test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
python-version: [3.6, 3.7, 3.8, 3.9]
15+
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
1616
experimental: [false]
17-
include:
18-
- python-version: 3.10-dev
19-
experimental: true
20-
2117
steps:
2218
- uses: actions/checkout@v2
2319
- name: Set up Python ${{ matrix.python-version }}

.readthedocs.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
3+
build:
4+
os: ubuntu-22.04
5+
tools:
6+
python: "3.11"
7+
8+
sphinx:
9+
configuration: docs/conf.py
10+
11+
python:
12+
install:
13+
- requirements: docs/requirements.txt

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#### 4.2
2+
* **Added Python 3.10 support**
3+
* Added ability to set individual borders' type via the `border_type` argument
4+
when creating a `Styler` object
5+
* Fixes [GitHub issue #108](https://github.com/DeepSpace2/StyleFrame/issues/108) - Styling and exporting a dataframe that
6+
contains a column called "index"
7+
* Fixes error when attempting to use `best_fit` argument in `StyleFrame.to_excel`
8+
on an empty dataframe [GitHub PR #157](https://github.com/DeepSpace2/StyleFrame/pull/157)
9+
110
#### 4.1
211
* Added `strikethrough` and `italic` to `Styler`
312
* Raising `TypeError` in `to_excel` if trying to use a non-openpyxl engine

README.md

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
[![Codecov branch](https://img.shields.io/codecov/c/github/DeepSpace2/StyleFrame/master.svg?style=plastic)]()
2-
[![Travis branch](https://img.shields.io/travis/DeepSpace2/StyleFrame/master.svg?style=plastic)]()
3-
[![PyPI](https://img.shields.io/pypi/v/styleframe.svg?style=plastic)]()
4-
[![PyPI](https://img.shields.io/pypi/pyversions/StyleFrame.svg?style=plastic)]()
5-
[![Downloads](http://pepy.tech/badge/styleframe)](http://pepy.tech/count/styleframe)
1+
[![codecov](https://codecov.io/gh/DeepSpace2/StyleFrame/branch/master/graph/badge.svg?token=f4Q048ZOwC)](https://codecov.io/gh/DeepSpace2/StyleFrame)
2+
[![GitHub Actions](https://img.shields.io/github/checks-status/deepspace2/styleframe/master?label=Tests&logo=github&style=plastic)](https://github.com/DeepSpace2/StyleFrame/actions/workflows/test.yml?query=branch%3Amaster)
3+
[![PyPI](https://img.shields.io/pypi/v/styleframe.svg?style=plastic)](https://pypi.org/project/styleframe/)
4+
![PyPI](https://img.shields.io/pypi/pyversions/StyleFrame.svg?style=plastic)
5+
[![Downloads](http://pepy.tech/badge/styleframe)](https://pepy.tech/project/styleframe)
66
[![Documentation Status](https://readthedocs.org/projects/styleframe/badge/?version=latest&style=plastic)](https://styleframe.readthedocs.io/en/latest/?badge=latest)
77

88
# StyleFrame
99
_Exporting DataFrames to a styled Excel file has never been so easy_
1010

11-
1211
A library that wraps pandas and openpyxl and allows easy styling of dataframes in Excel.
1312

14-
[Documentation](http://styleframe.readthedocs.org/en/latest/) and [Changelog](CHANGELOG.md)
13+
- [Documentation](http://styleframe.readthedocs.org/en/latest/)
14+
- [Changelog](CHANGELOG.md)
15+
- [How to contribute](.github/CONTRIBUTING.md)
1516

1617
---
1718

@@ -48,45 +49,18 @@ $ pip install styleframe
4849
## Basics
4950

5051
* ***Styler***:
51-
```python
52-
__init__(self, bg_color=None, bold=False, font=utils.fonts.arial, font_size=12, font_color=None,
53-
number_format=utils.number_formats.general, protection=False, underline=None,
54-
border_type=utils.borders.thin, horizontal_alignment=utils.horizontal_alignments.center,
55-
vertical_alignment=utils.vertical_alignments.center, wrap_text=True, shrink_to_fit=True,
56-
fill_pattern_type=utils.fill_pattern_types.solid, indent=0,
57-
comment_author=None, comment_text=None, text_rotation=0)
58-
```
59-
Object that represents the style of a cell in our excel file.
60-
Styler is responsible of storing the style of single cell.
61-
Once the style is ready, ```.to_openpyxl_style()``` method is called.
52+
The `Styler` class represents a style of a cell.
6253

6354
* ***utils***:
64-
```python
65-
from styleframe import utils
66-
```
67-
Before you start to style your StyleFrame, take a look in the utils module.
68-
You may find there very useful things such as number formats, colors, borders and more!
69-
55+
The `utils` module contains helper classes for frequently used styling elements,
56+
such as number and date formats, colors and border types.
7057

7158
* ***Container***:
72-
```python
73-
__init__(self, value, styler=None)
74-
```
75-
Object that represents cell in our excel file.
76-
it contains two variables:
77-
    - value which may be anything you wish to put in the cell as long as excel file support its format.
78-
    - style which is the style of the cell- created by ```Styler(...).to_openpyxl_style()```
79-
80-
And finally:
59+
The `Container` class represents a cell, a value/style pair.
8160

8261
* ***StyleFrame***:
83-
```python
84-
__init__(self, obj, styler_obj=None):
85-
```
86-
StyleFrame is the main object we will be dealing with.
87-
It contains self DataFrame which is based on the given obj.
88-
Each item of the self DataFrame is wrapped by a Container object to store the given data and its` style.
89-
StyleFrame (usually referred as sf) reveals a very easy api for styling.
62+
The `StyleFrame` is the main interaction point you will have.
63+
It wraps the `DataFrame` object you will be styling.
9064

9165
## Usage Examples
9266

@@ -141,11 +115,14 @@ sf.apply_style_by_indexes(indexes_to_style=sf[sf['Pass/Fail'] == 'Failed'],
141115
sf.set_column_width(columns=sf.columns, width=20)
142116
sf.set_row_height(rows=sf.row_indexes, height=25)
143117

144-
sf.to_excel('output.xlsx',
145-
# Add filters in row 0 to each column.
146-
row_to_add_filters=0,
147-
# Freeze the columns before column 'A' (=None) and rows above '2' (=1).
148-
columns_and_rows_to_freeze='A2').save()
118+
writer = sf.to_excel('output.xlsx',
119+
# Add filters in row 0 to each column.
120+
row_to_add_filters=0,
121+
# Freeze the columns before column 'A' (=None)
122+
# and rows above '2' (=1).
123+
columns_and_rows_to_freeze='A2')
124+
125+
writer.close()
149126
```
150127
The final output saved under output.xlsx:
151128
![Example 1](readme-images/example1.PNG?raw=true)
@@ -224,7 +201,7 @@ from styleframe import Styler, utils
224201

225202

226203
sf.apply_column_style(cols_to_style='Date',
227-
styler_obj=Styler(number_format=utils.number_formats.date,
204+
styler_obj=Styler(date_format=utils.number_formats.date,
228205
font=utils.fonts.calibri,
229206
bold=True))
230207

@@ -263,7 +240,7 @@ Change the background of all rows where the date is after 14/1/2000 to green
263240
sf.apply_style_by_indexes(indexes_to_style=sf[sf['Date'] > date(2000, 1, 14)],
264241
cols_to_style='Date',
265242
styler_obj=Styler(bg_color=utils.colors.green,
266-
number_format=utils.number_formats.date,
243+
date_format=utils.number_formats.date,
267244
bold=True))
268245
```
269246

@@ -285,14 +262,14 @@ sf.to_excel(excel_writer=ew,
285262
Adding another excel sheet
286263
```python
287264
other_sheet_sf = StyleFrame({'Dates': [date(2016, 10, 20), date(2016, 10, 21), date(2016, 10, 22)]},
288-
styler_obj=Styler(number_format=utils.number_formats.date))
265+
styler_obj=Styler(date_format=utils.number_formats.date))
289266

290267
other_sheet_sf.to_excel(excel_writer=ew, sheet_name='2')
291268
```
292269

293270
Don't forget to save
294271
```python
295-
ew.save()
272+
ew.close()
296273
```
297274

298275
**_the result:_**

docs/requirements.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
colour
1+
openpyxl>=2.5,<4
2+
colour>=0.1.5,<0.2
23
jsonschema
3-
openpyxl
4-
pandas
5-
sphinx==5.0.1
6-
xlrd
4+
pandas<3
5+
xlrd>=1.0.0,<1.3.0 ; python_version<='3.6'
6+
sphinx==7.2.6
7+
sphinx-rtd-theme

docs/usage_examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Creating ExcelWriter object:
2424

2525
ew = StyleFrame.ExcelWriter(r'C:\my_excel.xlsx')
2626
sf.to_excel(ew)
27-
ew.save()
27+
ew.close()
2828

2929
It is also possible to style a whole column or columns, and decide whether to style the headers or not:
3030
::

docs/utils.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ It is possible to directly use a value that is not present in the utils module a
1616
.. autoclass:: styleframe.utils.borders
1717
:members:
1818

19+
.. autoclass:: styleframe.utils.border_locations
20+
:members:
21+
1922
.. autoclass:: styleframe.utils.horizontal_alignments
2023
:members:
2124

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def find_version(*file_paths):
6767
'Programming Language :: Python :: 3.6',
6868
'Programming Language :: Python :: 3.7',
6969
'Programming Language :: Python :: 3.8',
70-
'Programming Language :: Python :: 3.9'
70+
'Programming Language :: Python :: 3.9',
71+
'Programming Language :: Python :: 3.10'
7172
],
7273

7374
# What does your project relate to?
@@ -86,7 +87,7 @@ def find_version(*file_paths):
8687
'openpyxl>=2.5,<4',
8788
'colour>=0.1.5,<0.2',
8889
'jsonschema',
89-
'pandas<2',
90+
'pandas<3',
9091
"xlrd>=1.0.0,<1.3.0 ; python_version<='3.6'"
9192
]
9293
)

styleframe/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sys
22

3+
from pandas import DataFrame
4+
35
from .container import Container
46
from .series import Series
57
from .style_frame import StyleFrame
@@ -14,3 +16,7 @@
1416

1517
ExcelWriter = StyleFrame.ExcelWriter
1618
read_excel = StyleFrame.read_excel
19+
20+
# applymap is deprecated in pandas > 2, nasty hack to support < 2 and > 2 versions at the same time
21+
if not hasattr(DataFrame, 'map'):
22+
DataFrame.map = DataFrame.applymap

0 commit comments

Comments
 (0)