Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepSpace2 committed Dec 26, 2017
2 parents f2d61ec + 54eb7eb commit 840c655
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.3.1: - Improved error message if invalid style arguments are used in JSON through the commandline interface
- Fixed an error importing utils in case there is already a utils module in Python's path (see github issue #31)

1.3: - Added utils.fill_pattern_types
- Added wrap_text, shrink_to_fit, fill_pattern_type and indent to Styler

Expand Down
25 changes: 19 additions & 6 deletions StyleFrame/commandline.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import argparse
import json
from collections import defaultdict

import inspect
import pandas as pd
import sys

from collections import defaultdict
from StyleFrame import StyleFrame, Container, Styler, version

PY2 = sys.version_info[0] == 2

if PY2:
styler_kwargs = set(inspect.getargspec(Styler.__init__).args)
styler_kwargs.remove('self')
else:
styler_kwargs = set(inspect.signature(Styler).parameters.keys())


class CommandLineInterface(object):
def __init__(self, input_path=None, output_path=None, input_json=None):
Expand Down Expand Up @@ -45,10 +54,14 @@ def _load_sheet(self, sheet):
if col_width:
self.col_names_to_width[sheet_name][col_name] = col_width
for cell in col['cells']:
data[col_name].append(Container(cell['value'], Styler(**(cell.get('style')
or col.get('style')
or default_cell_style
or {})).create_style()))
provided_style = cell.get('style') or col.get('style') or default_cell_style or {}
unrecognized_styler_kwargs = set(provided_style.keys()) - styler_kwargs
if unrecognized_styler_kwargs:
raise TypeError('Styler dict {} contains unexpected argument: {}.\n'
'Expected arguments: {}'.format(provided_style, unrecognized_styler_kwargs,
styler_kwargs))
else:
data[col_name].append(Container(cell['value'], Styler(**(provided_style)).create_style()))
sf = StyleFrame(pd.DataFrame(data=data))

self._apply_headers_style(sf, sheet)
Expand Down
14 changes: 7 additions & 7 deletions StyleFrame/style_frame.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# coding:utf-8
import sys
import pandas as pd

import datetime as dt
import numpy as np
from openpyxl import cell, load_workbook
import pandas as pd
import sys

from . import utils
from copy import deepcopy
import datetime as dt
from openpyxl import cell, load_workbook

PY2 = sys.version_info[0] == 2

Expand All @@ -16,15 +19,12 @@
from series import Series
# noinspection PyUnresolvedReferences
from styler import Styler
# noinspection PyUnresolvedReferences
import utils

# Python 3
else:
from StyleFrame.container import Container
from StyleFrame.styler import Styler
from StyleFrame.series import Series
from StyleFrame import utils

try:
pd_timestamp = pd.Timestamp
Expand Down
5 changes: 1 addition & 4 deletions StyleFrame/styler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# coding:utf-8
from openpyxl.styles import PatternFill, Style, Color, Border, Side, Font, Alignment, Protection

try: # python2
import utils
except ImportError: # python3
from StyleFrame import utils
from . import utils


class Styler(object):
Expand Down
2 changes: 1 addition & 1 deletion StyleFrame/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_all_versions():
return _versions_


_version_ = '1.3'
_version_ = '1.3.1'
_python_version_ = get_python_version()
_pandas_version_ = get_pandas_version()
_openpyxl_version_ = get_openpyxl_version()
Expand Down

0 comments on commit 840c655

Please sign in to comment.