Skip to content

Commit 0203805

Browse files
committed
Bug with Matrix match find and fixed
1 parent 95eb02f commit 0203805

1 file changed

Lines changed: 37 additions & 12 deletions

File tree

src/diffupy/matrix.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ def validate_labels(self):
157157
def update_ix_mappings(self):
158158
"""Return a copy of Matrix Object."""
159159
if hasattr(self, '_rows_labels_ix_mapping') and self.rows_labels:
160-
_rows_labels_ix_mapping = get_label_ix_mapping(self.rows_labels)
160+
self._rows_labels_ix_mapping = get_label_ix_mapping(self.rows_labels)
161+
161162
if hasattr(self, '_cols_labels_ix_mapping') and hasattr(self, '_cols_labels'):
162-
_cols_labels_ix_mapping = get_label_ix_mapping(self._cols_labels)
163+
self._cols_labels_ix_mapping = get_label_ix_mapping(self._cols_labels)
163164

164165
def validate_labels_and_update_ix_mappings(self):
165166
"""Return a copy of Matrix Object."""
@@ -254,24 +255,32 @@ def cols_idx_scores_mapping(self, cols_idx_scores_mapping):
254255
self._rows_idx_scores_mapping = cols_idx_scores_mapping
255256
self._cols_idx_scores_mapping = cols_idx_scores_mapping
256257

257-
"""Getters from labels"""
258-
259-
def set_row_from_label(self, label, x):
260-
"""Set row from label."""
261-
self.mat[self.rows_labels_ix_mapping[label]] = x
258+
"""Getters setters and delete from labels"""
262259

263260
def get_row_from_label(self, label):
264261
"""Get row from labels."""
265262
return self.mat[self.rows_labels_ix_mapping[label]]
266263

267-
def set_col_from_label(self, label, x):
268-
"""Set col from label."""
269-
self.mat[:, self.cols_labels_ix_mapping[label]] = x
264+
def set_row_from_label(self, label, x):
265+
"""Set row from label."""
266+
self.mat[self.rows_labels_ix_mapping[label]] = x
267+
268+
def delete_row_from_label(self, label):
269+
"""Set row from label."""
270+
self.mat = np.delete(self.mat, self.rows_labels_ix_mapping[label], 0)
271+
self.rows_labels.remove(label)
272+
self.update_ix_mappings()
270273

271274
def get_col_from_label(self, label):
272275
"""Get col from labels."""
273276
return self.mat[:, self.cols_labels_ix_mapping[label]]
274277

278+
def delete_col_from_label(self, label):
279+
"""Set col from label."""
280+
self.mat = np.delete(self.mat, self.cols_labels_ix_mapping[:, self.cols_labels_ix_mapping[label]], 1)
281+
self.cols_labels.remove(label)
282+
self.update_ix_mappings()
283+
275284
def set_cell_from_labels(self, row_label, col_label, x):
276285
"""Set cell from labels."""
277286
self.mat[self.rows_labels_ix_mapping[row_label], self.cols_labels_ix_mapping[col_label]] = x
@@ -372,7 +381,7 @@ def match_mat(self, reference_matrix, match_quadratic=None):
372381

373382
return mat_match
374383

375-
def match_missing_rows(self, reference_labels, missing_fill):
384+
def match_missing_rows(self, reference_labels, missing_fill = 0):
376385
"""Match method to set missing rows labels from reference labels with the missing_fill value."""
377386
if reference_labels == self.rows_labels:
378387
return self
@@ -391,6 +400,22 @@ def match_missing_rows(self, reference_labels, missing_fill):
391400

392401
return mat_match
393402

403+
def match_delete_rows(self, reference_labels):
404+
"""Match method to set missing rows labels from reference labels with the missing_fill value."""
405+
if reference_labels == self.rows_labels:
406+
return self
407+
408+
mat_match = self.__copy__()
409+
410+
over_labels = set(mat_match.rows_labels) - set(reference_labels)
411+
412+
for label in over_labels:
413+
mat_match.delete_row_from_label(label)
414+
415+
mat_match.validate_labels_and_update_ix_mappings()
416+
417+
return mat_match
418+
394419
def match_missing_cols(self, reference_labels, missing_fill):
395420
"""Match method to set missing cols labels from reference labels with the missing_fill value."""
396421
if reference_labels == self.cols_labels:
@@ -402,7 +427,7 @@ def match_missing_cols(self, reference_labels, missing_fill):
402427

403428
mat_match.cols_labels.append(missing_labels)
404429

405-
missing_values = np.array([len(missing_labels), len(reference_labels.cols_labels)])
430+
missing_values = np.array([len(self.rows_labels), len(reference_labels.cols_labels)])
406431
missing_values.fill(missing_fill)
407432

408433
mat_match.mat = np.concatenate(mat_match.mat, missing_values, axis=1)

0 commit comments

Comments
 (0)