@@ -117,8 +117,7 @@ def shape(self):
117117 # Shape is stored as a numpy.array:
118118 arrayshape = self .attrs ["SHAPE" ]
119119 # which must be converted to a tuple:
120- realshape = (arrayshape [0 ], arrayshape [1 ])
121- self ._shape = realshape
120+ self ._shape = (arrayshape [0 ], arrayshape [1 ])
122121 return self ._shape
123122
124123 # Inspect the first Dataset object to determine its shape
@@ -133,22 +132,19 @@ def shape(self):
133132 if self .mode != "r" :
134133 storeshape = np .array ([self ._shape [0 ], self ._shape [1 ]], dtype = "int32" )
135134 self .attrs ["SHAPE" ] = storeshape
135+ self .flush ()
136136
137137 return self ._shape
138- return None
138+ raise ShapeError ( "File shape is not set." )
139139
140140 def list_matrices (self ):
141- """
142- List the matrix names in this File
143- """
141+ """List the matrix names in this File"""
144142 if super (File , self ).__contains__ ("data" ):
145143 return list (super (File , self ).__getitem__ ("data" ).keys ())
146144 return []
147145
148146 def list_all_attributes (self ):
149- """
150- Return set of all attributes used for any Matrix in this File
151- """
147+ """Return set of all attributes used for any Matrix in this File"""
152148 all_tags = set ()
153149 if super (File , self ).__contains__ ("data" ):
154150 data_group = super (File , self ).__getitem__ ("data" )
@@ -174,61 +170,55 @@ def delete_mapping(self, title):
174170 try :
175171 lookup = super (File , self ).__getitem__ ("lookup" )
176172 del lookup [title ]
173+ self .flush ()
177174 except Exception :
178175 raise LookupError (f"No such mapping: { title } " )
179176
180- def mapping (self , title ):
181- """
182- Return dict containing key:value pairs for specified mapping.
183- """
177+ def delete_matrix (self , name ):
178+ """Remove a matrix."""
184179 try :
185- # fetch entries
186- if not super (File , self ).__contains__ ("lookup" ):
187- raise LookupError (f"No such mapping: { title } " )
180+ data_group = super (File , self ).__getitem__ ("data" )
181+ del data_group [name ]
182+ self .flush ()
183+ except Exception :
184+ raise LookupError (f"No such matrix: { name } " )
188185
189- lookup = super (File , self ).__getitem__ ("lookup" )
190- if title not in lookup :
191- raise LookupError (f"No such mapping: { title } " )
186+ def mapping (self , title ):
187+ """Return dict containing key:value pairs for specified mapping."""
188+ # fetch entries
189+ if not super (File , self ).__contains__ ("lookup" ):
190+ raise LookupError (f"No such mapping: { title } " )
192191
193- entries = lookup [title ][:]
192+ lookup = super (File , self ).__getitem__ ("lookup" )
193+ if title not in lookup :
194+ raise LookupError (f"No such mapping: { title } " )
194195
195- # build reverse key-lookup
196- keymap = {}
197- for i in range (len (entries )):
198- keymap [entries [i ]] = i
196+ entries = lookup [title ][:]
199197
200- return keymap
198+ # build reverse key-lookup
199+ keymap = {}
200+ for i in range (len (entries )):
201+ keymap [entries [i ]] = i
201202
202- except Exception as e :
203- if isinstance (e , LookupError ):
204- raise e
205- raise LookupError (f"No such mapping: { title } " )
203+ return keymap
206204
207205 def map_entries (self , title ):
208206 """Return a list of entries for the specified mapping."""
209- try :
210- if not super (File , self ).__contains__ ("lookup" ):
211- raise LookupError (f"No such mapping: { title } " )
207+ if not super (File , self ).__contains__ ("lookup" ):
208+ raise LookupError (f"No such mapping: { title } " )
212209
213- lookup = super (File , self ).__getitem__ ("lookup" )
214- if title not in lookup :
215- raise LookupError (f"No such mapping: { title } " )
216-
217- entries = lookup [title ][:]
218- # Convert to list if it's a numpy array
219- if hasattr (entries , "tolist" ):
220- return entries .tolist ()
221- return entries
222-
223- except Exception as e :
224- if isinstance (e , LookupError ):
225- raise e
210+ lookup = super (File , self ).__getitem__ ("lookup" )
211+ if title not in lookup :
226212 raise LookupError (f"No such mapping: { title } " )
227213
214+ entries = lookup [title ][:]
215+ # Convert to list if it's a numpy array
216+ if hasattr (entries , "tolist" ):
217+ return entries .tolist ()
218+ return entries
219+
228220 def create_mapping (self , title , entries , overwrite = False ):
229- """
230- Create an equivalency index.
231- """
221+ """Create an equivalency index."""
232222
233223 # Enforce shape-checking
234224 if self .shape ():
0 commit comments