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
1918from larray .inout .session import ext_default_engine , get_file_handler
19+ from larray .util .misc import float_error_handler_factory , is_interactive_interpreter , renamed_to , inverseop , basestring
20+
21+
22+ def _get_handler (engine , fname , overwrite , ** kwargs ):
23+ if engine == 'auto' :
24+ _ , ext = os .path .splitext (fname )
25+ ext = ext .strip ('.' ) if '.' in ext else 'csv'
26+ engine = ext_default_engine [ext ]
27+ if engine == 'hdf' :
28+ engine_hdf = 'auto'
29+ if '_hdf' in engine :
30+ engine_hdf , engine = engine .split ('_' )
31+ handler_cls = get_file_handler (engine )
32+ if engine == 'pandas_csv' and 'sep' in kwargs :
33+ handler = handler_cls (fname , overwrite , kwargs ['sep' ])
34+ elif engine == 'hdf' :
35+ handler = handler_cls (fname , overwrite , engine = engine_hdf )
36+ else :
37+ handler = handler_cls (fname , overwrite )
38+ return handler
2039
2140
2241# XXX: inherit from OrderedDict or LArray?
@@ -358,7 +377,7 @@ def load(self, fname, names=None, engine='auto', display=False, **kwargs):
358377 List of objects to load.
359378 If `fname` is None, list of paths to CSV files.
360379 Defaults to all valid objects present in the file/directory.
361- engine : {'auto', 'pandas_csv', 'pandas_hdf', 'pandas_excel', 'xlwings_excel', 'pickle'}, optional
380+ engine : {'auto', 'pandas_csv', 'pandas_hdf', 'tables_hdf', ' pandas_excel', 'xlwings_excel', 'pickle'}, optional
362381 Load using `engine`. Defaults to 'auto' (use default engine for the format guessed from the file extension).
363382 display : bool, optional
364383 Whether or not to display which file is being worked on. Defaults to False.
@@ -415,15 +434,7 @@ def load(self, fname, names=None, engine='auto', display=False, **kwargs):
415434 engine = ext_default_engine ['csv' ]
416435 else :
417436 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 )
423- if engine == 'pandas_csv' and 'sep' in kwargs :
424- handler = handler_cls (fname , kwargs ['sep' ])
425- else :
426- handler = handler_cls (fname )
437+ handler = _get_handler (engine , fname , False , ** kwargs )
427438 metadata , objects = handler .read (names , display = display , ** kwargs )
428439 for k , v in objects .items ():
429440 self [k ] = v
@@ -442,7 +453,7 @@ def save(self, fname, names=None, engine='auto', overwrite=True, display=False,
442453 List of names of LArray/Axis/Group objects to dump.
443454 If `fname` is None, list of paths to CSV files.
444455 Defaults to all objects present in the Session.
445- engine : {'auto', 'pandas_csv', 'pandas_hdf', 'pandas_excel', 'xlwings_excel', 'pickle'}, optional
456+ engine : {'auto', 'pandas_csv', 'pandas_hdf', 'tables_hdf', ' pandas_excel', 'xlwings_excel', 'pickle'}, optional
446457 Dump using `engine`. Defaults to 'auto' (use default engine for the format guessed from the file extension).
447458 overwrite: bool, optional
448459 Whether or not to overwrite an existing file, if any. Ignored for CSV files and 'pandas_excel' engine.
@@ -482,15 +493,7 @@ def save(self, fname, names=None, engine='auto', overwrite=True, display=False,
482493 >>> # replace arr1 and add arr4 in file output.h5
483494 >>> s2.save('output.h5', overwrite=False) # doctest: +SKIP
484495 """
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 )
490- if engine == 'pandas_csv' and 'sep' in kwargs :
491- handler = handler_cls (fname , overwrite , kwargs ['sep' ])
492- else :
493- handler = handler_cls (fname , overwrite )
496+ handler = _get_handler (engine , fname , overwrite , ** kwargs )
494497 meta = self .meta if overwrite else None
495498 items = self .items ()
496499 if names is not None :
0 commit comments