Skip to content

BUG/CI/TST: fix format strings #7285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/requirements-2.6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ sqlalchemy==0.8.1
scipy==0.11.0
statsmodels==0.4.3
xlwt==0.7.5
openpyxl==1.6.2
openpyxl==2.0.3
xlsxwriter==0.4.6
xlrd==0.9.2
1 change: 0 additions & 1 deletion ci/requirements-3.2.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
python-dateutil==2.1
pytz==2013b
openpyxl==1.6.2
xlsxwriter==0.4.6
xlrd==0.9.2
numpy==1.7.1
Expand Down
2 changes: 2 additions & 0 deletions doc/source/v0.14.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ users upgrade to this version.

API changes
~~~~~~~~~~~
- Openpyxl now raises a ValueError on construction of the openpyxl writer
instead of warning on pandas import (:issue:`7284`).

.. _whatsnew_0141.prior_deprecations:

Expand Down
22 changes: 10 additions & 12 deletions pandas/compat/openpyxl_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@
start_ver = '1.6.1'
stop_ver = '2.0.0'


def is_compat():
"""
Detect whether the installed version of openpyxl is supported
Returns True/False if openpyxl is installed, None otherwise
"""
try:
import openpyxl
except ImportError:
return None
"""Detect whether the installed version of openpyxl is supported.

Returns
-------
compat : bool
``True`` if openpyxl is installed and is between versions 1.6.1 and
2.0.0, ``False`` otherwise.
"""
import openpyxl
ver = LooseVersion(openpyxl.__version__)
if ver < LooseVersion(start_ver) or LooseVersion(stop_ver) <= ver:
return False

return True
return LooseVersion(start_ver) < ver <= LooseVersion(stop_ver)
12 changes: 6 additions & 6 deletions pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ class _OpenpyxlWriter(ExcelWriter):
supported_extensions = ('.xlsx', '.xlsm')

def __init__(self, path, engine=None, **engine_kwargs):
if not openpyxl_compat.is_compat():
raise ValueError('Installed openpyxl is not supported at this '
'time. Use >={0} and '
'<{1}.'.format(openpyxl_compat.start_ver,
openpyxl_compat.stop_ver))
# Use the openpyxl module as the Excel writer.
from openpyxl.workbook import Workbook

Expand Down Expand Up @@ -618,12 +623,7 @@ def _convert_to_style(cls, style_dict):

return xls_style


if openpyxl_compat.is_compat():
register_writer(_OpenpyxlWriter)
else:
warn('Installed openpyxl is not supported at this time. Use >={} and <{}.'
.format(openpyxl_compat.start_ver, openpyxl_compat.stop_ver))
register_writer(_OpenpyxlWriter)


class _XlwtWriter(ExcelWriter):
Expand Down
48 changes: 36 additions & 12 deletions pandas/io/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os
from distutils.version import LooseVersion

import operator
import functools
import nose

from numpy import nan
Expand Down Expand Up @@ -45,10 +47,6 @@ def _skip_if_no_openpyxl():
except ImportError:
raise nose.SkipTest('openpyxl not installed, skipping')

if not openpyxl_compat.is_compat():
raise nose.SkipTest('need %s <= openpyxl < %s, skipping' %
(openpyxl_compat.start_ver, openpyxl_compat.stop_ver))


def _skip_if_no_xlsxwriter():
try:
Expand Down Expand Up @@ -884,7 +882,6 @@ def test_to_excel_output_encoding(self):
result = read_excel(filename, 'TestSheet', encoding='utf8')
tm.assert_frame_equal(result, df)


def test_to_excel_unicode_filename(self):
_skip_if_no_xlrd()
with ensure_clean(u('\u0192u.') + self.ext) as filename:
Expand Down Expand Up @@ -1094,13 +1091,36 @@ def test_swapped_columns(self):
tm.assert_series_equal(write_frame['B'], read_frame['B'])


def raise_wrapper(orig_method):
@functools.wraps(orig_method)
def wrapped(self, *args, **kwargs):
_skip_if_no_openpyxl()
if openpyxl_compat.is_compat():
orig_method(self, *args, **kwargs)
else:
msg = 'Installed openpyxl is not supported at this time\. Use.+'
with tm.assertRaisesRegexp(ValueError, msg):
orig_method(self, *args, **kwargs)
return wrapped


def raise_on_incompat_version(cls):
methods = filter(operator.methodcaller('startswith', 'test_'), dir(cls))
for method in methods:
setattr(cls, method, raise_wrapper(getattr(cls, method)))
return cls


@raise_on_incompat_version
class OpenpyxlTests(ExcelWriterBase, tm.TestCase):
ext = '.xlsx'
engine_name = 'openpyxl'
check_skip = staticmethod(_skip_if_no_openpyxl)
check_skip = staticmethod(lambda *args, **kwargs: None)

def test_to_excel_styleconverter(self):
_skip_if_no_openpyxl()
if not openpyxl_compat.is_compat():
raise nose.SkipTest('incompatiable openpyxl version')

import openpyxl

Expand All @@ -1114,17 +1134,17 @@ def test_to_excel_styleconverter(self):
xlsx_style = _OpenpyxlWriter._convert_to_style(hstyle)
self.assertTrue(xlsx_style.font.bold)
self.assertEqual(openpyxl.style.Border.BORDER_THIN,
xlsx_style.borders.top.border_style)
xlsx_style.borders.top.border_style)
self.assertEqual(openpyxl.style.Border.BORDER_THIN,
xlsx_style.borders.right.border_style)
xlsx_style.borders.right.border_style)
self.assertEqual(openpyxl.style.Border.BORDER_THIN,
xlsx_style.borders.bottom.border_style)
xlsx_style.borders.bottom.border_style)
self.assertEqual(openpyxl.style.Border.BORDER_THIN,
xlsx_style.borders.left.border_style)
xlsx_style.borders.left.border_style)
self.assertEqual(openpyxl.style.Alignment.HORIZONTAL_CENTER,
xlsx_style.alignment.horizontal)
xlsx_style.alignment.horizontal)
self.assertEqual(openpyxl.style.Alignment.VERTICAL_TOP,
xlsx_style.alignment.vertical)
xlsx_style.alignment.vertical)


class XlwtTests(ExcelWriterBase, tm.TestCase):
Expand Down Expand Up @@ -1160,6 +1180,7 @@ class XlsxWriterTests(ExcelWriterBase, tm.TestCase):
check_skip = staticmethod(_skip_if_no_xlsxwriter)


@raise_on_incompat_version
class OpenpyxlTests_NoMerge(ExcelWriterBase, tm.TestCase):
ext = '.xlsx'
engine_name = 'openpyxl'
Expand Down Expand Up @@ -1196,6 +1217,8 @@ def test_ExcelWriter_dispatch(self):
import xlsxwriter
writer_klass = _XlsxWriter
except ImportError:
if not openpyxl_compat.is_compat():
raise nose.SkipTest('incompatible openpyxl version')
_skip_if_no_openpyxl()
writer_klass = _OpenpyxlWriter

Expand Down Expand Up @@ -1246,6 +1269,7 @@ def check_called(func):
check_called(lambda: df.to_excel('something.xls', engine='dummy'))
set_option('io.excel.xlsx.writer', val)


if __name__ == '__main__':
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
exit=False)