Skip to content

Enh tests compat pytables 2.1 #137

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

Closed
Closed
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
22 changes: 18 additions & 4 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
except ImportError:
raise nose.SkipTest('no pytables')

from distutils.version import LooseVersion

_default_compressor = LooseVersion(tables.__version__) >= '2.2' \
and 'blosc' or 'zlib'

class TesttHDFStore(unittest.TestCase):
path = '__test__.h5'
scratchpath = '__scratch__.h5'
Expand Down Expand Up @@ -82,16 +87,25 @@ def test_put(self):

def test_put_compression(self):
df = tm.makeTimeDataFrame()
self.store.put('c', df, table=True, compression='blosc')
tm.assert_frame_equal(self.store['c'], df)

self.store.put('c', df, table=True, compression='zlib')
tm.assert_frame_equal(self.store['c'], df)

# can't compress if table=False
self.assertRaises(ValueError, self.store.put, 'b', df,
table=False, compression='zlib')

def test_put_compression_blosc(self):
tm.skip_if_no_package('tables', '2.2', app='blosc support')
df = tm.makeTimeDataFrame()

# can't compress if table=False
self.assertRaises(ValueError, self.store.put, 'b', df,
table=False, compression='blosc')

self.store.put('c', df, table=True, compression='blosc')
tm.assert_frame_equal(self.store['c'], df)

def test_put_integer(self):
# non-date, non-string index
df = DataFrame(np.random.randn(50, 100))
Expand Down Expand Up @@ -346,7 +360,7 @@ def test_select_filter_corner(self):
def _check_roundtrip(self, obj, comparator, compression=False):
options = {}
if compression:
options['complib'] = 'blosc'
options['complib'] = _default_compressor

store = HDFStore(self.scratchpath, 'w', **options)
try:
Expand All @@ -360,7 +374,7 @@ def _check_roundtrip(self, obj, comparator, compression=False):
def _check_roundtrip_table(self, obj, comparator, compression=False):
options = {}
if compression:
options['complib'] = 'blosc'
options['complib'] = _default_compressor

store = HDFStore(self.scratchpath, 'w', **options)
try:
Expand Down
65 changes: 65 additions & 0 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import string
import sys

from distutils.version import LooseVersion

from numpy.random import randn
import numpy as np

Expand Down Expand Up @@ -216,3 +218,66 @@ def makeLongPanel():

return wp.to_long()

# Dependency checks. Copied this from Nipy/Nipype (Copyright of
# respective developers, license: BSD-3)
def package_check(pkg_name, version=None, app='pandas', checker=LooseVersion,
exc_failed_import=ImportError,
exc_failed_check=RuntimeError):
"""Check that the minimal version of the required package is installed.

Parameters
----------
pkg_name : string
Name of the required package.
version : string, optional
Minimal version number for required package.
app : string, optional
Application that is performing the check. For instance, the
name of the tutorial being executed that depends on specific
packages.
checker : object, optional
The class that will perform the version checking. Default is
distutils.version.LooseVersion.
exc_failed_import : Exception, optional
Class of the exception to be thrown if import failed.
exc_failed_check : Exception, optional
Class of the exception to be thrown if version check failed.

Examples
--------
package_check('numpy', '1.3')
package_check('networkx', '1.0', 'tutorial1')

"""

if app:
msg = '%s requires %s' % (app, pkg_name)
else:
msg = 'module requires %s' % pkg_name
if version:
msg += ' with version >= %s' % (version,)
try:
mod = __import__(pkg_name)
except ImportError:
raise exc_failed_import(msg)
if not version:
return
try:
have_version = mod.__version__
except AttributeError:
raise exc_failed_check('Cannot find version for %s' % pkg_name)
if checker(have_version) < checker(version):
raise exc_failed_check(msg)

def skip_if_no_package(*args, **kwargs):
"""Raise SkipTest if package_check fails

Parameters
----------
*args Positional parameters passed to `package_check`
*kwargs Keyword parameters passed to `package_check`
"""
from nose import SkipTest
package_check(exc_failed_import=SkipTest,
exc_failed_check=SkipTest,
*args, **kwargs)