Skip to content

Commit

Permalink
Complete migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Nov 7, 2023
1 parent 53f767f commit e8addb7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 38 deletions.
5 changes: 2 additions & 3 deletions src/biocutils/_utils_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ def _check_array_dimensions(x, active: int) -> bool:
current = x[i].shape
if len(first) != len(current):
raise ValueError("inconsistent dimensions for combining arrays (expected " + str(len(first)) + ", got " + str(len(current)) + " for array " + str(i) + ")")

for j in enumerate(first):
if j != active and first[active] != current[active]:
for j in range(len(first)):
if j != active and first[j] != current[j]:
raise ValueError("inconsistent dimension extents for combining arrays on dimension " + str(active) + " (expected " + str(first[active]) + ", got " + str(current[active]) + " for array " + str(i) + ")")


Expand Down
4 changes: 2 additions & 2 deletions src/biocutils/convert_to_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def _convert_sparse_to_dense(x):
return x.todense()

try:
convert_to_dense.register(sp.sparray, _convert_sparse_to_dense)
convert_to_dense.register(sp.spmatrix, _convert_sparse_to_dense)
except Exception:
pass

try:
combine_rows.register(sp.spmatrix, _convert_sparse_to_dense)
convert_to_dense.register(sp.sparray, _convert_sparse_to_dense)
except Exception:
pass
14 changes: 9 additions & 5 deletions tests/test_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ def test_basic_list():
def test_basic_mixed_dense_list():
x = [1, 2, 3]
y = [0.1, 0.2]
xd = np.array([1, 2, 3])

xd = np.array(x)
zcomb = combine(xd, y)

z = x + y

assert zcomb == z
assert isinstance(zcomb, list)
assert (zcomb == z).all()
assert len(zcomb) == len(xd) + len(y)


def test_basic_mixed_dense_array():
x = np.array([1, 2, 3, 4]).reshape((2,2))
y = np.array([4, 5, 6, 7]).reshape((2,2))
zcomb = combine(x, y)
assert zcomb.shape == (4, 2)
1 change: 1 addition & 0 deletions tests/test_combine_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_combine_columns_mixed():
x = np.ones(shape=(num_rows, 10))
y = sp.identity(num_rows)

print(x, y)
z = combine_columns(x, y)

assert isinstance(z, np.ndarray)
Expand Down
30 changes: 2 additions & 28 deletions tests/test_combine_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def test_basic_mixed_dense_list():
zcomb = combine_sequences(xd, y)

z = x + y

assert zcomb == z
assert isinstance(zcomb, list)
assert (zcomb == z).all()
assert len(zcomb) == len(xd) + len(y)


Expand All @@ -57,34 +55,10 @@ def test_basic_mixed_tuple_list():
zcomb = combine_sequences(xd, y, x)

z = x + list(y) + x

assert zcomb == z
assert isinstance(zcomb, list)
assert (zcomb == z).all()
assert len(zcomb) == 2 * len(xd) + len(y)


def test_basic_sparse():
x = np.array([1, 2, 3])
y = np.array([0.1, 0.2])

sx = sp.csr_array(x)
sy = sp.csr_array(y)

z = combine_sequences(sx, sy)

assert isinstance(z, sp.spmatrix)
assert z.shape[1] == len(x) + len(y)

# mixed sparse arrays
sx = sp.csr_array(x)
sy = sp.coo_array(y)

z = combine_sequences(sx, sy)

assert isinstance(z, sp.spmatrix)
assert z.shape[1] == len(x) + len(y)


def test_pandas_series():
s1 = pd.Series(["a", "b"])
s2 = pd.Series(["c", "d"])
Expand Down

0 comments on commit e8addb7

Please sign in to comment.