@@ -107,7 +107,7 @@ def from_pandas_df(self, pandas_df):
107107
108108 for _ , col_name in enumerate (pandas_df .columns ):
109109 newvalue = pandas_df [col_name ].to_numpy ()
110- self . __setitem__ ( col_name , newvalue )
110+ self [ col_name ] = newvalue
111111
112112 def from_numpy_array (self , numpy_array ):
113113 """Build attributes of NavData using np.ndarray.
@@ -125,7 +125,7 @@ def from_numpy_array(self, numpy_array):
125125 self .build_navdata ()
126126
127127 for row_num in range (numpy_array .shape [0 ]):
128- self . __setitem__ ( str (row_num ), numpy_array [row_num ,:])
128+ self [ str (row_num )] = numpy_array [row_num ,:]
129129
130130 @staticmethod
131131 def _row_map ():
@@ -277,7 +277,8 @@ def __getitem__(self, key_idx):
277277 -------
278278 arr_slice : np.ndarray
279279 Array of data containing row names and time indexed
280- columns
280+ columns. The return is squeezed meaning that all dimensions
281+ of the output that are length of one are removed
281282 """
282283 rows , cols = self ._parse_key_idx (key_idx )
283284 row_list , row_str = self ._get_str_rows (rows )
@@ -293,6 +294,10 @@ def __getitem__(self, key_idx):
293294 # arr_slice.append(str_arr[ cols])
294295 else :
295296 arr_slice = self .array [rows , cols ]
297+
298+ # remove all dimensions of length one
299+ arr_slice = np .squeeze (arr_slice )
300+
296301 return arr_slice
297302
298303 def __setitem__ (self , key_idx , newvalue ):
@@ -330,7 +335,7 @@ def __setitem__(self, key_idx, newvalue):
330335 else :
331336 # print("\n",key_idx,"\n")#,newvalue)
332337 if not isinstance (newvalue , int ) and not isinstance (newvalue , float ):
333- assert not isinstance (np .asarray (newvalue )[ 0 ] , str ), \
338+ assert not isinstance (np .asarray (newvalue ). item ( 0 ) , str ), \
334339 "Cannot set a row with list of strings, please use np.ndarray with dtype=object"
335340 # Adding numeric values
336341 self .str_map [key_idx ] = {}
@@ -408,7 +413,10 @@ def _str_2_val(self, new_str_vals, newvalue, key):
408413 dtype = self .arr_dtype )
409414 # Set unassigned value to int not accessed by string map
410415 for str_key , str_val in str_dict .items ():
411- new_str_vals [newvalue == str_val ] = str_key
416+ if new_str_vals .size == 1 :
417+ new_str_vals = np .array (str_key ,dtype = self .arr_dtype )
418+ else :
419+ new_str_vals [newvalue == str_val ] = str_key
412420 # Copy set to false to prevent memory overflows
413421 new_str_vals = np .round (new_str_vals .astype (self .arr_dtype ,
414422 copy = False ))
@@ -693,7 +701,10 @@ def fillna(self, array):
693701
694702 """
695703 nan_str = np .array ([np .nan ]).astype (str )[0 ]
696- array [np .where (array .astype (str )== nan_str )] = ""
704+ if array .size > 1 :
705+ array [np .where (array .astype (str )== nan_str )] = ""
706+ elif array .size == 1 and array == nan_str :
707+ array = np .array ("" )
697708
698709 def rename (self , mapper ):
699710 """Rename rows of NavData class.
0 commit comments