11# -*- coding: utf-8 -*-
22from __future__ import absolute_import , division , print_function
33
4+ import fnmatch
45import os
5- import sys
66import re
7- import fnmatch
7+ import sys
88import warnings
99from collections import OrderedDict , Iterable
1010
1111import numpy as np
1212
13- from larray .core .metadata import Metadata
14- from larray .core .group import Group
13+ from larray .core .array import LArray , get_axes , ndtest , zeros , zeros_like , sequence
1514from larray .core .axis import Axis
1615from larray .core .constants import nan
17- from larray .core .array import LArray , get_axes , ndtest , zeros , zeros_like , sequence , aslarray
18- from larray .util .misc import float_error_handler_factory , is_interactive_interpreter , renamed_to , inverseop , basestring
16+ from larray .core .group import Group
17+ from larray .core .metadata import Metadata
18+ from larray .inout .hdf import _get_hdf_engine
1919from larray .inout .session import ext_default_engine , get_file_handler
20+ from larray .util .misc import float_error_handler_factory , is_interactive_interpreter , renamed_to , inverseop , basestring
21+
22+
23+ def _get_handler_cls (engine , fname ):
24+ if engine == 'auto' :
25+ _ , ext = os .path .splitext (fname )
26+ ext = ext .strip ('.' ) if '.' in ext else 'csv'
27+ if ext in ['h5' , 'hdf' ]:
28+ engine = _get_hdf_engine (fname ) + '_hdf'
29+ else :
30+ engine = ext_default_engine [ext ]
31+ handler_cls = get_file_handler (engine )
32+ return handler_cls
2033
2134
2235# XXX: inherit from OrderedDict or LArray?
@@ -358,7 +371,7 @@ def load(self, fname, names=None, engine='auto', display=False, **kwargs):
358371 List of objects to load.
359372 If `fname` is None, list of paths to CSV files.
360373 Defaults to all valid objects present in the file/directory.
361- engine : {'auto', 'pandas_csv', 'pandas_hdf', 'pandas_excel', 'xlwings_excel', 'pickle'}, optional
374+ engine : {'auto', 'pandas_csv', 'pandas_hdf', 'tables_hdf', ' pandas_excel', 'xlwings_excel', 'pickle'}, optional
362375 Load using `engine`. Defaults to 'auto' (use default engine for the format guessed from the file extension).
363376 display : bool, optional
364377 Whether or not to display which file is being worked on. Defaults to False.
@@ -415,11 +428,7 @@ def load(self, fname, names=None, engine='auto', display=False, **kwargs):
415428 engine = ext_default_engine ['csv' ]
416429 else :
417430 raise ValueError ("List of paths to only CSV files expected. Got {}" .format (names ))
418- if engine == 'auto' :
419- _ , ext = os .path .splitext (fname )
420- ext = ext .strip ('.' ) if '.' in ext else 'csv'
421- engine = ext_default_engine [ext ]
422- handler_cls = get_file_handler (engine )
431+ handler_cls = _get_handler_cls (engine , fname )
423432 if engine == 'pandas_csv' and 'sep' in kwargs :
424433 handler = handler_cls (fname , kwargs ['sep' ])
425434 else :
@@ -442,7 +451,7 @@ def save(self, fname, names=None, engine='auto', overwrite=True, display=False,
442451 List of names of LArray/Axis/Group objects to dump.
443452 If `fname` is None, list of paths to CSV files.
444453 Defaults to all objects present in the Session.
445- engine : {'auto', 'pandas_csv', 'pandas_hdf', 'pandas_excel', 'xlwings_excel', 'pickle'}, optional
454+ engine : {'auto', 'pandas_csv', 'pandas_hdf', 'tables_hdf', ' pandas_excel', 'xlwings_excel', 'pickle'}, optional
446455 Dump using `engine`. Defaults to 'auto' (use default engine for the format guessed from the file extension).
447456 overwrite: bool, optional
448457 Whether or not to overwrite an existing file, if any. Ignored for CSV files and 'pandas_excel' engine.
@@ -482,11 +491,7 @@ def save(self, fname, names=None, engine='auto', overwrite=True, display=False,
482491 >>> # replace arr1 and add arr4 in file output.h5
483492 >>> s2.save('output.h5', overwrite=False) # doctest: +SKIP
484493 """
485- if engine == 'auto' :
486- _ , ext = os .path .splitext (fname )
487- ext = ext .strip ('.' ) if '.' in ext else 'csv'
488- engine = ext_default_engine [ext ]
489- handler_cls = get_file_handler (engine )
494+ handler_cls = _get_handler_cls (engine , fname )
490495 if engine == 'pandas_csv' and 'sep' in kwargs :
491496 handler = handler_cls (fname , overwrite , kwargs ['sep' ])
492497 else :
0 commit comments