1
1
# -*- coding: utf-8 -*-
2
2
from __future__ import absolute_import , division , print_function
3
3
4
+ import fnmatch
4
5
import os
5
- import sys
6
6
import re
7
- import fnmatch
7
+ import sys
8
8
import warnings
9
9
from collections import OrderedDict , Iterable
10
10
11
11
import numpy as np
12
12
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
15
14
from larray .core .axis import Axis
16
15
from 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
19
19
from 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
20
33
21
34
22
35
# XXX: inherit from OrderedDict or LArray?
@@ -358,7 +371,7 @@ def load(self, fname, names=None, engine='auto', display=False, **kwargs):
358
371
List of objects to load.
359
372
If `fname` is None, list of paths to CSV files.
360
373
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
362
375
Load using `engine`. Defaults to 'auto' (use default engine for the format guessed from the file extension).
363
376
display : bool, optional
364
377
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):
415
428
engine = ext_default_engine ['csv' ]
416
429
else :
417
430
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 )
423
432
if engine == 'pandas_csv' and 'sep' in kwargs :
424
433
handler = handler_cls (fname , kwargs ['sep' ])
425
434
else :
@@ -442,7 +451,7 @@ def save(self, fname, names=None, engine='auto', overwrite=True, display=False,
442
451
List of names of LArray/Axis/Group objects to dump.
443
452
If `fname` is None, list of paths to CSV files.
444
453
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
446
455
Dump using `engine`. Defaults to 'auto' (use default engine for the format guessed from the file extension).
447
456
overwrite: bool, optional
448
457
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,
482
491
>>> # replace arr1 and add arr4 in file output.h5
483
492
>>> s2.save('output.h5', overwrite=False) # doctest: +SKIP
484
493
"""
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 )
490
495
if engine == 'pandas_csv' and 'sep' in kwargs :
491
496
handler = handler_cls (fname , overwrite , kwargs ['sep' ])
492
497
else :
0 commit comments