18
18
from pandas .sparse .api import SparseSeries , SparseDataFrame , SparsePanel
19
19
from pandas .sparse .array import BlockIndex , IntIndex
20
20
from pandas .tseries .api import PeriodIndex , DatetimeIndex
21
- from pandas .core .common import adjoin
21
+ from pandas .core .common import adjoin , isnull
22
22
from pandas .core .algorithms import match , unique , factorize
23
23
from pandas .core .categorical import Categorical
24
24
from pandas .core .common import _asarray_tuplesafe , _try_sort
@@ -727,8 +727,8 @@ def _create_storer(self, group, value = None, table = False, append = False, **k
727
727
""" return a suitable Storer class to operate """
728
728
729
729
def error (t ):
730
- raise Exception ("cannot properly create the storer for: [%s] [group->%s,value->%s,table->%s,append->%s,kwargs->%s]" %
731
- (t ,group ,type (value ),table ,append ,kwargs ))
730
+ raise NotImplementedError ("cannot properly create the storer for: [%s] [group->%s,value->%s,table->%s,append->%s,kwargs->%s]" %
731
+ (t ,group ,type (value ),table ,append ,kwargs ))
732
732
733
733
pt = getattr (group ._v_attrs ,'pandas_type' ,None )
734
734
tt = getattr (group ._v_attrs ,'table_type' ,None )
@@ -768,7 +768,12 @@ def error(t):
768
768
if value is not None :
769
769
770
770
if pt == 'frame_table' :
771
- tt = 'appendable_frame' if value .index .nlevels == 1 else 'appendable_multiframe'
771
+ index = getattr (value ,'index' ,None )
772
+ if index is not None :
773
+ if index .nlevels == 1 :
774
+ tt = 'appendable_frame'
775
+ elif index .nlevels > 1 :
776
+ tt = 'appendable_multiframe'
772
777
elif pt == 'wide_table' :
773
778
tt = 'appendable_panel'
774
779
elif pt == 'ndim_table' :
@@ -1187,7 +1192,23 @@ def get_atom_string(self, block, itemsize):
1187
1192
1188
1193
def set_atom_string (self , block , existing_col , min_itemsize , nan_rep ):
1189
1194
# fill nan items with myself
1190
- data = block .fillna (nan_rep ).values
1195
+ block = block .fillna (nan_rep )
1196
+ data = block .values
1197
+
1198
+ # see if we have a valid string type
1199
+ inferred_type = lib .infer_dtype (data .ravel ())
1200
+ if inferred_type != 'string' :
1201
+
1202
+ # we cannot serialize this data, so report an exception on a column by column basis
1203
+ for item in block .items :
1204
+
1205
+ col = block .get (item )
1206
+ inferred_type = lib .infer_dtype (col .ravel ())
1207
+ if inferred_type != 'string' :
1208
+ raise NotImplementedError ("cannot serialize the column [%s] because "
1209
+ "its data contents are [%s] object dtype" %
1210
+ (item ,inferred_type ))
1211
+
1191
1212
1192
1213
# itemsize is the maximum length of a string (along any dimension)
1193
1214
itemsize = lib .max_len_string_array (data .ravel ())
@@ -2234,7 +2255,11 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None, data_columns=None,
2234
2255
2235
2256
# set the default axes if needed
2236
2257
if axes is None :
2237
- axes = _AXES_MAP [type (obj )]
2258
+ try :
2259
+ axes = _AXES_MAP [type (obj )]
2260
+ except :
2261
+ raise NotImplementedError ("cannot properly create the storer for: [group->%s,value->%s]" %
2262
+ (self .group ._v_name ,type (obj )))
2238
2263
2239
2264
# map axes to numbers
2240
2265
axes = [obj ._get_axis_number (a ) for a in axes ]
@@ -2251,7 +2276,7 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None, data_columns=None,
2251
2276
2252
2277
# currently support on ndim-1 axes
2253
2278
if len (axes ) != self .ndim - 1 :
2254
- raise Exception ("currenctly only support ndim-1 indexers in an AppendableTable" )
2279
+ raise Exception ("currently only support ndim-1 indexers in an AppendableTable" )
2255
2280
2256
2281
# create according to the new data
2257
2282
self .non_index_axes = []
@@ -2335,10 +2360,18 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None, data_columns=None,
2335
2360
name = b .items [0 ]
2336
2361
self .data_columns .append (name )
2337
2362
2338
- try :
2339
- existing_col = existing_table .values_axes [
2340
- i ] if existing_table is not None and validate else None
2363
+ # make sure that we match up the existing columns
2364
+ # if we have an existing table
2365
+ if existing_table is not None and validate :
2366
+ try :
2367
+ existing_col = existing_table .values_axes [i ]
2368
+ except :
2369
+ raise Exception ("Incompatible appended table [%s] with existing table [%s]" %
2370
+ (blocks ,existing_table .values_axes ))
2371
+ else :
2372
+ existing_col = None
2341
2373
2374
+ try :
2342
2375
col = klass .create_for_block (
2343
2376
i = i , name = name , version = self .version )
2344
2377
col .set_atom (block = b ,
0 commit comments