-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: GH18498 - Split test_pytables into sub-modules #19735
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
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f148d0c
TST: GH18498: Move existing tests out of test_pytables module
f9ecbf3
TST: GH18498: Removed io/test_pytables module
65419ce
TST: GH:18498 Move legacy hdf data files into pytables sub-module
27e8cc4
TST: GH:18498 Move test methods into sub-modules
bd75829
TST: GH:18498 Conditionally test with tables import
5052897
TST: GH18498 Requested pull request changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import os | ||
import tempfile | ||
from contextlib import contextmanager | ||
from distutils.version import LooseVersion | ||
|
||
import pytest | ||
import pandas.util.testing as tm | ||
from pandas.io.pytables import HDFStore | ||
|
||
tables = pytest.importorskip('tables') | ||
_default_compressor = ('blosc' if LooseVersion(tables.__version__) >= | ||
LooseVersion('2.2') else 'zlib') | ||
|
||
|
||
def get_file_name(): | ||
""" Create a file name for test data files """ | ||
return 'tmp.__%s__.h5' % tm.rands(10) | ||
|
||
|
||
def create_tempfile(file_name=None): | ||
""" Create an unopened named temporary file """ | ||
if file_name is None: | ||
file_name = get_file_name() | ||
return os.path.join(tempfile.gettempdir(), file_name) | ||
|
||
|
||
@contextmanager | ||
def ensure_clean_path(path=None): | ||
""" | ||
return essentially a named temporary file that is not opened | ||
and deleted on existing; if path is a list, then create and | ||
return list of filenames | ||
""" | ||
try: | ||
if isinstance(path, list): | ||
filenames = [create_tempfile(p) for p in path] | ||
yield filenames | ||
else: | ||
filenames = [create_tempfile(path)] | ||
yield filenames[0] | ||
finally: | ||
for f in filenames: | ||
safe_remove(f) | ||
|
||
|
||
@contextmanager | ||
def ensure_clean_store(path=None, mode='a', complevel=None, complib=None, | ||
fletcher32=False): | ||
|
||
try: | ||
if path is None: | ||
path = create_tempfile(path) | ||
|
||
store = HDFStore(path, mode=mode, complevel=complevel, | ||
complib=complib, fletcher32=False) | ||
yield store | ||
finally: | ||
safe_close(store) | ||
if mode == 'w' or mode == 'a': | ||
safe_remove(path) | ||
|
||
|
||
def safe_remove(path): | ||
if path is not None: | ||
try: | ||
os.remove(path) | ||
except: | ||
pass | ||
|
||
|
||
def safe_close(store): | ||
try: | ||
if store is not None: | ||
store.close() | ||
except: | ||
pass | ||
|
||
|
||
def _maybe_remove(store, key): | ||
"""For tests using tables, try removing the table to be sure there is | ||
no content from previous tests using the same table name.""" | ||
try: | ||
store.remove(key) | ||
except: | ||
pass | ||
|
||
|
||
def _check_roundtrip(obj, comparator, compression=False, **kwargs): | ||
options = {} | ||
if compression: | ||
options['complib'] = _default_compressor | ||
|
||
with ensure_clean_store('w', **options) as store: | ||
store['obj'] = obj | ||
retrieved = store['obj'] | ||
comparator(retrieved, obj, **kwargs) | ||
|
||
|
||
def _check_double_roundtrip(obj, comparator, compression=False, **kwargs): | ||
options = {} | ||
if compression: | ||
options['complib'] = compression or _default_compressor | ||
|
||
with ensure_clean_store('w', **options) as store: | ||
store['obj'] = obj | ||
retrieved = store['obj'] | ||
comparator(retrieved, obj, **kwargs) | ||
store['obj'] = retrieved | ||
again = store['obj'] | ||
comparator(again, obj, **kwargs) | ||
|
||
|
||
def _check_roundtrip_table(obj, comparator, compression=False): | ||
options = {} | ||
if compression: | ||
options['complib'] = _default_compressor | ||
|
||
with ensure_clean_store('w', **options) as store: | ||
store.put('obj', obj, format='table') | ||
retrieved = store['obj'] | ||
|
||
comparator(retrieved, obj) |
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if things are not used here, remove them