-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add shape check to Dataset initialization #106
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
04b7dbb
Check input array shapes when Dataset is initialized
JulioAPeraza d3f9e9b
Add test for nimare.utils._check_inputs_shape
JulioAPeraza d73271a
Cover two missing lines by the test
JulioAPeraza cffebb4
Add test when n or v is None
JulioAPeraza 86a1eb5
Remove extra clause
JulioAPeraza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
"""Tests for pymare.utils.""" | ||
import os.path as op | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from pymare import utils | ||
|
||
|
||
def test_get_resource_path(): | ||
"""Test nimare.utils.get_resource_path.""" | ||
print(utils.get_resource_path()) | ||
assert op.isdir(utils.get_resource_path()) | ||
|
||
|
||
def test_check_inputs_shape(): | ||
"""Test nimare.utils._check_inputs_shape.""" | ||
n_rows = 5 | ||
n_columns = 4 | ||
n_pred = 3 | ||
y = np.random.randint(1, 100, size=(n_rows, n_columns)) | ||
v = np.random.randint(1, 100, size=(n_rows + 1, n_columns)) | ||
n = np.random.randint(1, 100, size=(n_rows, n_columns)) | ||
X = np.random.randint(1, 100, size=(n_rows, n_pred)) | ||
X_names = [f"X{x}" for x in range(n_pred)] | ||
|
||
utils._check_inputs_shape(y, X, "y", "X", row=True) | ||
utils._check_inputs_shape(y, n, "y", "n", row=True, column=True) | ||
utils._check_inputs_shape(X, np.array(X_names)[None, :], "X", "X_names", column=True) | ||
|
||
# Raise error if the number of rows and columns of v don't match y | ||
with pytest.raises(ValueError): | ||
utils._check_inputs_shape(y, v, "y", "v", row=True, column=True) | ||
|
||
# Raise error if neither row or column is True | ||
with pytest.raises(ValueError): | ||
utils._check_inputs_shape(y, n, "y", "n") | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I know I approved already, but I just realized that, while the function allows Nones, that behavior isn't tested here. Can you test Nones? Not every Dataset will have
v
orn
.