Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused code #111

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,9 @@
concatenate_varying_shape_arrays,
fill_dataset,
remove_nan_rows,
split_varying_shape_array,
)


@pytest.mark.parametrize(
["a", "b", "c", "result"],
[
[
np.array([1]),
np.array([1, 2]),
np.array([1, 2, 3]),
np.array([[1, np.nan, np.nan], [1, 2, np.nan], [1, 2, 3]]),
],
[
np.array([[1, 2]]),
np.array([[1, 2], [1, 2]]),
np.array([[1, 2], [1, 2], [1, 2]]),
np.array(
[
[[1, 2], [np.nan, np.nan], [np.nan, np.nan]],
[[1, 2], [1, 2], [np.nan, np.nan]],
[[1, 2], [1, 2], [1, 2]],
]
),
],
],
)
def test_concatenate_split_varying_shape_arrays(a, b, c, result):
assert np.array_equal(
concatenate_varying_shape_arrays([a, b, c]), result, equal_nan=True
)

a1, a2, a3 = split_varying_shape_array(result)

assert np.array_equal(a1, a)
assert np.array_equal(a2, b)
assert np.array_equal(a3, c)


def test_concatenate_split_varying_shape_arrays_empty():
a = np.array([1, 2])
b = np.array([])
Expand All @@ -55,11 +19,6 @@ def test_concatenate_split_varying_shape_arrays_empty():
concatenate_varying_shape_arrays([a, b, c]), result, equal_nan=True
)

a, b, c = split_varying_shape_array(result)
assert np.array_equal(a, np.array([1, 2]))
assert np.array_equal(b, np.array([]))
assert np.array_equal(c, np.array([4, 5, 6]))


@pytest.mark.parametrize(
["a", "b", "result"],
Expand Down
27 changes: 0 additions & 27 deletions znh5md/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,6 @@ def remove_nan_rows(array: np.ndarray) -> np.ndarray | None:
return array[~np.isnan(array).all(axis=tuple(range(1, array.ndim)))]


def split_varying_shape_array(array: np.ndarray) -> list[np.ndarray]:
"""Split a numpy array into a list of 1D arrays.

NaN values are removed to yield arrays of varying lengths.

Parameters
----------
array (numpy.array): At least 2D numpy array.

Returns
-------
list of numpy.array: A list of numpy arrays where
each array corresponds to a row in the input array.

Example:
>>> split_varying_shape_array(np.array([[ 1., 2., np.nan], [ 3., 4., 5.]]))
[array([1., 2.]), array([3., 4., 5.])]

"""
arrays = []
for row in array:
valid_elements = remove_nan_rows(row)
arrays.append(valid_elements)

return arrays


def fill_dataset(dataset, new_data):
# Axis 0 is the configuration axis
# Axis 1 is the number of particles axis
Expand Down
Loading