@@ -100,6 +100,23 @@ class DuplicateWarning(Warning):
100100map directly to c-types [inferred_type->%s,key->%s] [items->%s]
101101"""
102102
103+ # formats
104+ _FORMAT_MAP = {
105+ u ('s' ) : 's' ,
106+ u ('storer' ) : 's' ,
107+ u ('t' ) : 't' ,
108+ u ('table' ) : 't' ,
109+ }
110+
111+ fmt_deprecate_doc = """
112+ the table keyword has been deprecated
113+ use the fmt='s|t' keyword instead
114+ s : specifies the Storer format
115+ and is the default for put operations
116+ t : specifies the Table format
117+ and is the default for append operations
118+ """
119+
103120# map object types
104121_TYPE_MAP = {
105122
@@ -545,7 +562,7 @@ def select_as_coordinates(self, key, where=None, start=None, stop=None, **kwargs
545562
546563 def unique (self , key , column , ** kwargs ):
547564 warnings .warn ("unique(key,column) is deprecated\n "
548- "use select_column(key,column).unique() instead" )
565+ "use select_column(key,column).unique() instead" , FutureWarning )
549566 return self .get_storer (key ).read_column (column = column , ** kwargs ).unique ()
550567
551568 def select_column (self , key , column , ** kwargs ):
@@ -641,24 +658,28 @@ def func(_start, _stop):
641658
642659 return TableIterator (self , func , nrows = nrows , start = start , stop = stop , auto_close = auto_close ).get_values ()
643660
644- def put (self , key , value , table = None , append = False , ** kwargs ):
661+ def put (self , key , value , fmt = None , append = False , ** kwargs ):
645662 """
646663 Store object in HDFStore
647664
648665 Parameters
649666 ----------
650667 key : object
651668 value : {Series, DataFrame, Panel}
652- table : boolean, default False
653- Write as a PyTables Table structure which may perform worse but
654- allow more flexible operations like searching / selecting subsets
655- of the data
669+ fmt : 's|t', default is 's' for storer format
670+ s : storer format
671+ Fast writing/reading. Not-appendable, nor searchable
672+ t : table format
673+ Write as a PyTables Table structure which may perform worse but
674+ allow more flexible operations like searching / selecting subsets
675+ of the data
656676 append : boolean, default False
657677 For table data structures, append the input data to the existing
658678 table
659679 encoding : default None, provide an encoding for strings
660680 """
661- self ._write_to_group (key , value , table = table , append = append , ** kwargs )
681+ kwargs = self ._validate_format (fmt or 's' , kwargs )
682+ self ._write_to_group (key , value , append = append , ** kwargs )
662683
663684 def remove (self , key , where = None , start = None , stop = None ):
664685 """
@@ -709,7 +730,7 @@ def remove(self, key, where=None, start=None, stop=None):
709730 'can only remove with where on objects written as tables' )
710731 return s .delete (where = where , start = start , stop = stop )
711732
712- def append (self , key , value , columns = None , append = True , ** kwargs ):
733+ def append (self , key , value , fmt = None , append = True , columns = None , ** kwargs ):
713734 """
714735 Append to Table in file. Node must already exist and be Table
715736 format.
@@ -718,6 +739,11 @@ def append(self, key, value, columns=None, append=True, **kwargs):
718739 ----------
719740 key : object
720741 value : {Series, DataFrame, Panel, Panel4D}
742+ fmt : 't', default is 't' for table format
743+ t : table format
744+ Write as a PyTables Table structure which may perform worse but
745+ allow more flexible operations like searching / selecting subsets
746+ of the data
721747 append : boolean, default True, append the input data to the existing
722748 data_columns : list of columns to create as data columns, or True to use all columns
723749 min_itemsize : dict of columns that specify minimum string sizes
@@ -735,7 +761,7 @@ def append(self, key, value, columns=None, append=True, **kwargs):
735761 raise Exception (
736762 "columns is not a supported keyword in append, try data_columns" )
737763
738- kwargs [ 'table' ] = True
764+ kwargs = self . _validate_format ( fmt or 't' , kwargs )
739765 self ._write_to_group (key , value , append = append , ** kwargs )
740766
741767 def append_to_multiple (self , d , value , selector , data_columns = None , axes = None , ** kwargs ):
@@ -901,13 +927,39 @@ def _check_if_open(self):
901927 if not self .is_open :
902928 raise ClosedFileError ("{0} file is not open!" .format (self ._path ))
903929
904- def _create_storer (self , group , value = None , table = False , append = False , ** kwargs ):
930+ def _validate_format (self , fmt , kwargs ):
931+ """ validate / deprecate formats; return the new kwargs """
932+ kwargs = kwargs .copy ()
933+
934+ if 'format' in kwargs :
935+ raise TypeError ("pls specify an object format with the 'fmt' keyword" )
936+
937+ # table arg
938+ table = kwargs .pop ('table' ,None )
939+
940+ if table is not None :
941+ warnings .warn (fmt_deprecate_doc ,FutureWarning )
942+
943+ if table :
944+ fmt = 't'
945+ else :
946+ fmt = 's'
947+
948+ # validate
949+ try :
950+ kwargs ['fmt' ] = _FORMAT_MAP [fmt .lower ()]
951+ except :
952+ raise TypeError ("invalid HDFStore format specified [{0}]" .format (fmt ))
953+
954+ return kwargs
955+
956+ def _create_storer (self , group , fmt = None , value = None , append = False , ** kwargs ):
905957 """ return a suitable Storer class to operate """
906958
907959 def error (t ):
908960 raise TypeError (
909- "cannot properly create the storer for: [%s] [group->%s,value->%s,table ->%s,append->%s,kwargs->%s]" %
910- (t , group , type (value ), table , append , kwargs ))
961+ "cannot properly create the storer for: [%s] [group->%s,value->%s,fmt ->%s,append->%s,kwargs->%s]" %
962+ (t , group , type (value ), fmt , append , kwargs ))
911963
912964 pt = _ensure_decoded (getattr (group ._v_attrs , 'pandas_type' , None ))
913965 tt = _ensure_decoded (getattr (group ._v_attrs , 'table_type' , None ))
@@ -931,7 +983,7 @@ def error(t):
931983 error ('_TYPE_MAP' )
932984
933985 # we are actually a table
934- if table or append :
986+ if fmt == 't' :
935987 pt += u ('_table' )
936988
937989 # a storer node
@@ -983,7 +1035,7 @@ def error(t):
9831035 error ('_TABLE_MAP' )
9841036
9851037 def _write_to_group (
986- self , key , value , index = True , table = False , append = False ,
1038+ self , key , value , fmt , index = True , append = False ,
9871039 complib = None , encoding = None , ** kwargs ):
9881040 group = self .get_node (key )
9891041
@@ -994,7 +1046,7 @@ def _write_to_group(
9941046
9951047 # we don't want to store a table node at all if are object is 0-len
9961048 # as there are not dtypes
997- if getattr (value ,'empty' ,None ) and (table or append ):
1049+ if getattr (value ,'empty' ,None ) and (fmt == 't' or append ):
9981050 return
9991051
10001052 if group is None :
@@ -1014,12 +1066,12 @@ def _write_to_group(
10141066 group = self ._handle .createGroup (path , p )
10151067 path = new_path
10161068
1017- s = self ._create_storer (group , value , table = table , append = append ,
1069+ s = self ._create_storer (group , fmt , value , append = append ,
10181070 encoding = encoding , ** kwargs )
10191071 if append :
10201072 # raise if we are trying to append to a non-table,
10211073 # or a table that exists (and we are putting)
1022- if not s .is_table or (s .is_table and table is None and s .is_exists ):
1074+ if not s .is_table or (s .is_table and fmt == 's' and s .is_exists ):
10231075 raise ValueError ('Can only append to Tables' )
10241076 if not s .is_exists :
10251077 s .set_object_info ()
0 commit comments