Skip to content

Commit

Permalink
naming updates to work with matchms
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-huber committed Oct 6, 2022
1 parent d2c7707 commit 17d3ece
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sparsestack/StackedSparseArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def to_array(self, name=None):
return array
array = np.zeros((self.__n_row, self.__n_col),
dtype=self.data.dtype)
array[self.row, self.col] = self.data
array[self.row, self.col] = self.data.reshape(-1)
return array

def to_coo(self, name):
Expand All @@ -396,11 +396,15 @@ def to_coo(self, name):


def update_structed_array_names(input_array: np.ndarray, name: str):
if len(input_array.dtype) > 1: # if structured array
if input_array.dtype.names is None: # no structured array
return np.array(input_array, dtype=[(name, input_array.dtype)])
if (name == "") or name is None:
dtype_new = np.dtype({'names': [f"{x}" for x in input_array.dtype.names],
'formats': [x[0] for x in input_array.dtype.fields.values()]})
else:
dtype_new = np.dtype({'names': [f"{name}_{x}" for x in input_array.dtype.names],
'formats': [x[0] for x in input_array.dtype.fields.values()]})
return input_array.astype(dtype_new)
return np.array(input_array, dtype=[(name, input_array.dtype)])
return input_array.astype(dtype_new)


def _unpack_index(index):
Expand Down
2 changes: 2 additions & 0 deletions sparsestack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def set_and_fill_new_array(data1, data2, name,
new_dtype = [(dname, d[0]) for dname, d in data1.dtype.fields.items()]
if data2.dtype.names is None:
new_dtype += [(name, data2.dtype)]
elif (name == "") or name is None:
new_dtype += [(f"{dname}", d[0]) for dname, d in data2.dtype.fields.items()]
else:
new_dtype += [(f"{name}_{dname}", d[0]) for dname, d in data2.dtype.fields.items()]
data_join = np.zeros(shape=(length), dtype=new_dtype)
Expand Down

0 comments on commit 17d3ece

Please sign in to comment.