6464from larray .core .abstractbases import ABCLArray
6565from larray .core .expr import ExprNode
6666from larray .core .group import (Group , IGroup , LGroup , remove_nested_groups , _to_key , _to_keys ,
67- _range_to_slice , _translate_sheet_name , _translate_key_hdf )
67+ _range_to_slice , _translate_sheet_name , _translate_group_key_hdf )
6868from larray .core .axis import Axis , AxisReference , AxisCollection , X , _make_axis
6969from larray .util .misc import (table2str , size2str , basestring , izip , rproduct , ReprString , duplicates ,
7070 float_error_handler_factory , _isnoneslice , light_product , unique_list , common_type ,
71- renamed_to , deprecate_kwarg )
71+ renamed_to , deprecate_kwarg , LHDFStore )
7272
7373
7474nan = np .nan
@@ -5997,7 +5997,7 @@ def to_csv(self, filepath, sep=',', na_rep='', wide=True, value_name='value', dr
59975997 series = self .to_series (value_name , dropna is not None )
59985998 series .to_csv (filepath , sep = sep , na_rep = na_rep , header = True , ** kwargs )
59995999
6000- def to_hdf (self , filepath , key , * args , ** kwargs ):
6000+ def to_hdf (self , filepath , key ):
60016001 """
60026002 Writes array to a HDF file.
60036003
@@ -6009,17 +6009,31 @@ def to_hdf(self, filepath, key, *args, **kwargs):
60096009 filepath : str
60106010 Path where the hdf file has to be written.
60116011 key : str or Group
6012- Name of the array within the HDF file.
6013- *args
6014- **kargs
6012+ Key (path) of the array within the HDF file (see Notes below).
6013+
6014+ Notes
6015+ -----
6016+ Objects stored in a HDF file can be grouped together in `HDF groups`.
6017+ If an object 'my_obj' is stored in a HDF group 'my_group',
6018+ the key associated with this object is then 'my_group/my_obj'.
6019+ Be aware that a HDF group can have subgroups.
60156020
60166021 Examples
60176022 --------
60186023 >>> a = ndtest((2, 3))
6019- >>> a.to_hdf('test.h5', 'a') # doctest: +SKIP
6024+
6025+ Save an array
6026+
6027+ >>> a.to_hdf('test.h5', 'a') # doctest: +SKIP
6028+
6029+ Save an array in a specific HDF group
6030+
6031+ >>> a.to_hdf('test.h5', 'arrays/a') # doctest: +SKIP
60206032 """
6021- key = _translate_key_hdf (key )
6022- self .to_frame ().to_hdf (filepath , key , * args , ** kwargs )
6033+ key = _translate_group_key_hdf (key )
6034+ with LHDFStore (filepath ) as store :
6035+ store .put (key , self .to_frame ())
6036+ store .get_storer (key ).attrs .type = 'Array'
60236037
60246038 @deprecate_kwarg ('sheet_name' , 'sheet' )
60256039 def to_excel (self , filepath = None , sheet = None , position = 'A1' , overwrite_file = False , clear_sheet = False ,
@@ -6085,7 +6099,7 @@ def to_excel(self, filepath=None, sheet=None, position='A1', overwrite_file=Fals
60856099 engine = 'xlwings' if xw is not None else None
60866100
60876101 if engine == 'xlwings' :
6088- from larray .inout .excel import open_excel
6102+ from larray .inout .xw_excel import open_excel
60896103
60906104 close = False
60916105 new_workbook = False
@@ -7022,7 +7036,7 @@ def aslarray(a):
70227036 elif hasattr (a , '__larray__' ):
70237037 return a .__larray__ ()
70247038 elif isinstance (a , pd .DataFrame ):
7025- from larray .inout .array import from_frame
7039+ from larray .inout .pandas import from_frame
70267040 return from_frame (a )
70277041 else :
70287042 return LArray (a )
0 commit comments