@@ -686,10 +686,14 @@ def _read_index_node(self, node):
686686 def _write_array (self , group , key , value ):
687687 if key in group :
688688 self .handle .removeNode (group , key )
689-
690- #Transform needed to interface with pytables row/col notation
691- value = value .T
692-
689+
690+ # Transform needed to interface with pytables row/col notation
691+ empty_array = any (x == 0 for x in value .shape )
692+ transposed = False
693+ if not empty_array :
694+ value = value .T
695+ transposed = True
696+
693697 if self .filters is not None :
694698 atom = None
695699 try :
@@ -704,9 +708,10 @@ def _write_array(self, group, key, value):
704708 value .shape ,
705709 filters = self .filters )
706710 ca [:] = value
707- getattr (group , key )._v_attrs .transposed = True
711+ getattr (group , key )._v_attrs .transposed = transposed
708712 return
709713
714+
710715 if value .dtype .type == np .object_ :
711716 vlarr = self .handle .createVLArray (group , key ,
712717 _tables ().ObjectAtom ())
@@ -715,16 +720,16 @@ def _write_array(self, group, key, value):
715720 self .handle .createArray (group , key , value .view ('i8' ))
716721 getattr (group , key )._v_attrs .value_type = 'datetime64'
717722 else :
718- if any ( x == 0 for x in value . shape ) :
723+ if empty_array :
719724 # ugly hack for length 0 axes
720725 arr = np .empty ((1 ,) * value .ndim )
721726 self .handle .createArray (group , key , arr )
722727 getattr (group , key )._v_attrs .value_type = str (value .dtype )
723728 getattr (group , key )._v_attrs .shape = value .shape
724729 else :
725730 self .handle .createArray (group , key , value )
726-
727- getattr (group , key )._v_attrs .transposed = True
731+
732+ getattr (group , key )._v_attrs .transposed = transposed
728733
729734 def _write_table (self , group , items = None , index = None , columns = None ,
730735 values = None , append = False , compression = None ):
@@ -977,16 +982,17 @@ def _read_array(group, key):
977982 if shape is not None :
978983 # length 0 axis
979984 ret = np .empty (shape , dtype = dtype )
985+ else :
986+ ret = data
980987
981988 if dtype == 'datetime64' :
982- ret = np .array (data , dtype = 'M8[ns]' )
983- ret = data
984-
985- if transposed == True :
989+ ret = np .array (ret , dtype = 'M8[ns]' )
990+
991+ if transposed :
986992 return ret .T
987993 else :
988994 return ret
989-
995+
990996def _unconvert_index (data , kind ):
991997 if kind == 'datetime64' :
992998 index = DatetimeIndex (data )
0 commit comments