@@ -100,6 +100,23 @@ class DuplicateWarning(Warning):
100
100
map directly to c-types [inferred_type->%s,key->%s] [items->%s]
101
101
"""
102
102
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
+
103
120
# map object types
104
121
_TYPE_MAP = {
105
122
@@ -545,7 +562,7 @@ def select_as_coordinates(self, key, where=None, start=None, stop=None, **kwargs
545
562
546
563
def unique (self , key , column , ** kwargs ):
547
564
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 )
549
566
return self .get_storer (key ).read_column (column = column , ** kwargs ).unique ()
550
567
551
568
def select_column (self , key , column , ** kwargs ):
@@ -641,24 +658,28 @@ def func(_start, _stop):
641
658
642
659
return TableIterator (self , func , nrows = nrows , start = start , stop = stop , auto_close = auto_close ).get_values ()
643
660
644
- def put (self , key , value , table = None , append = False , ** kwargs ):
661
+ def put (self , key , value , fmt = None , append = False , ** kwargs ):
645
662
"""
646
663
Store object in HDFStore
647
664
648
665
Parameters
649
666
----------
650
667
key : object
651
668
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
656
676
append : boolean, default False
657
677
For table data structures, append the input data to the existing
658
678
table
659
679
encoding : default None, provide an encoding for strings
660
680
"""
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 )
662
683
663
684
def remove (self , key , where = None , start = None , stop = None ):
664
685
"""
@@ -709,7 +730,7 @@ def remove(self, key, where=None, start=None, stop=None):
709
730
'can only remove with where on objects written as tables' )
710
731
return s .delete (where = where , start = start , stop = stop )
711
732
712
- def append (self , key , value , columns = None , append = True , ** kwargs ):
733
+ def append (self , key , value , fmt = None , append = True , columns = None , ** kwargs ):
713
734
"""
714
735
Append to Table in file. Node must already exist and be Table
715
736
format.
@@ -718,6 +739,11 @@ def append(self, key, value, columns=None, append=True, **kwargs):
718
739
----------
719
740
key : object
720
741
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
721
747
append : boolean, default True, append the input data to the existing
722
748
data_columns : list of columns to create as data columns, or True to use all columns
723
749
min_itemsize : dict of columns that specify minimum string sizes
@@ -735,7 +761,7 @@ def append(self, key, value, columns=None, append=True, **kwargs):
735
761
raise Exception (
736
762
"columns is not a supported keyword in append, try data_columns" )
737
763
738
- kwargs [ 'table' ] = True
764
+ kwargs = self . _validate_format ( fmt or 't' , kwargs )
739
765
self ._write_to_group (key , value , append = append , ** kwargs )
740
766
741
767
def append_to_multiple (self , d , value , selector , data_columns = None , axes = None , ** kwargs ):
@@ -901,13 +927,39 @@ def _check_if_open(self):
901
927
if not self .is_open :
902
928
raise ClosedFileError ("{0} file is not open!" .format (self ._path ))
903
929
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 ):
905
957
""" return a suitable Storer class to operate """
906
958
907
959
def error (t ):
908
960
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 ))
911
963
912
964
pt = _ensure_decoded (getattr (group ._v_attrs , 'pandas_type' , None ))
913
965
tt = _ensure_decoded (getattr (group ._v_attrs , 'table_type' , None ))
@@ -931,7 +983,7 @@ def error(t):
931
983
error ('_TYPE_MAP' )
932
984
933
985
# we are actually a table
934
- if table or append :
986
+ if fmt == 't' :
935
987
pt += u ('_table' )
936
988
937
989
# a storer node
@@ -983,7 +1035,7 @@ def error(t):
983
1035
error ('_TABLE_MAP' )
984
1036
985
1037
def _write_to_group (
986
- self , key , value , index = True , table = False , append = False ,
1038
+ self , key , value , fmt , index = True , append = False ,
987
1039
complib = None , encoding = None , ** kwargs ):
988
1040
group = self .get_node (key )
989
1041
@@ -994,7 +1046,7 @@ def _write_to_group(
994
1046
995
1047
# we don't want to store a table node at all if are object is 0-len
996
1048
# 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 ):
998
1050
return
999
1051
1000
1052
if group is None :
@@ -1014,12 +1066,12 @@ def _write_to_group(
1014
1066
group = self ._handle .createGroup (path , p )
1015
1067
path = new_path
1016
1068
1017
- s = self ._create_storer (group , value , table = table , append = append ,
1069
+ s = self ._create_storer (group , fmt , value , append = append ,
1018
1070
encoding = encoding , ** kwargs )
1019
1071
if append :
1020
1072
# raise if we are trying to append to a non-table,
1021
1073
# 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 ):
1023
1075
raise ValueError ('Can only append to Tables' )
1024
1076
if not s .is_exists :
1025
1077
s .set_object_info ()
0 commit comments