-
Notifications
You must be signed in to change notification settings - Fork 262
RF+BF: Add tolerances and data types for nib-diff, remove hypothesis dependency #678
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
cd5a741
RF+ENH: nib-diff - allow to specify absolute and/or relative maximal …
yarikoptic 018eceb
ENH: nib-diff Field/File not just Field in the header
yarikoptic 833b4df
changed as commented out in the pull request
chrispycheng 9b123f6
changes as commented
chrispycheng 1e33ea7
RF: anticipated files of different shapes, fixed table display, corre…
chrispycheng 76ca32f
elaborated docstring, modified get_data_diff to allow direct array in…
chrispycheng 0aa6370
added to diff documentation, undid executable change, took out debugg…
chrispycheng d057249
undid permission snafu on test_scripts
chrispycheng 76ee358
docstring and function name clarification, change get_data to get_fda…
chrispycheng 034c276
corrected styles per Travis, limited fdata to float32
chrispycheng 19fcdd5
STY: Break overly-long line
effigies 93c7bb6
prepared for future PR to allow modification of dtype used in diff co…
chrispycheng cd85e09
Merge branch 'enh-diff' of https://github.com/yarikoptic/nibabel into…
chrispycheng 97ead00
added cmdline functionality for modifying datatype used for file data…
chrispycheng 2340a92
added testing for dtype at cmdline, assuming cmdline functionality. c…
chrispycheng e8d3a4f
RF: do not use hypothesis
yarikoptic 09cfef1
BF: properly compare NaNs and test for >2 arguments given to are_valu…
yarikoptic 1996ead
RF: long -> large, NaN -> nan
yarikoptic 0fb8920
BF: reintroduce try/except guarding around initial np.isnan
yarikoptic e4c5b52
BF: exception string matching for not implemented in numpy 1.7.1
yarikoptic e87d581
BF: another workaround for elderly numpy 1.7.1
yarikoptic f973ce4
BF(DOC): fixed damn trailing whitespaces in a docsting
yarikoptic 22f89e9
Merge branch 'no-hypothesis' of https://github.com/yarikoptic/nibabel…
chrispycheng 3636c4d
added tests to fix coverage problem
chrispycheng 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -2,4 +2,3 @@ | |
-r requirements.txt | ||
nose | ||
mock | ||
hypothesis |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -7,9 +7,6 @@ | |
from os.path import (dirname, join as pjoin, abspath) | ||
import numpy as np | ||
|
||
from hypothesis import given | ||
import hypothesis.strategies as st | ||
|
||
|
||
DATA_PATH = abspath(pjoin(dirname(__file__), 'data')) | ||
|
||
|
@@ -18,51 +15,59 @@ | |
# TODO: MAJOR TO DO IS TO FIGURE OUT HOW TO USE HYPOTHESIS FOR LONGER LIST LENGTHS WHILE STILL CONTROLLING FOR OUTCOMES | ||
|
||
|
||
@given(st.data()) | ||
def test_diff_values_int(data): | ||
x = data.draw(st.integers(), label='x') | ||
y = data.draw(st.integers(min_value=x + 1), label='x+1') | ||
z = data.draw(st.integers(max_value=x - 1), label='x-1') | ||
|
||
assert not are_values_different(x, x) | ||
assert are_values_different(x, y) | ||
assert are_values_different(x, z) | ||
assert are_values_different(y, z) | ||
|
||
|
||
@given(st.data()) | ||
def test_diff_values_float(data): | ||
x = data.draw(st.just(0), label='x') | ||
y = data.draw(st.floats(min_value=1e8), label='y') | ||
z = data.draw(st.floats(max_value=-1e8), label='z') | ||
def test_diff_values_int(): | ||
long = 10**30 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
assert not are_values_different(0, 0) | ||
assert not are_values_different(1, 1) | ||
assert not are_values_different(long, long) | ||
assert are_values_different(0, 1) | ||
assert are_values_different(1, 2) | ||
assert are_values_different(1, long) | ||
|
||
assert not are_values_different(x, x) | ||
assert are_values_different(x, y) | ||
assert are_values_different(x, z) | ||
assert are_values_different(y, z) | ||
|
||
def test_diff_values_float(): | ||
assert not are_values_different(0., 0.) | ||
assert not are_values_different(0., 0., 0.) # can take more | ||
assert not are_values_different(1.1, 1.1) | ||
assert are_values_different(0., 1.1) | ||
assert are_values_different(0., 0, 1.1) | ||
assert are_values_different(1., 2.) | ||
|
||
@given(st.data()) | ||
def test_diff_values_mixed(data): | ||
type_float = data.draw(st.floats(), label='float') | ||
type_int = data.draw(st.integers(), label='int') | ||
type_none = data.draw(st.none(), label='none') | ||
|
||
assert are_values_different(type_float, type_int) | ||
assert are_values_different(type_float, type_none) | ||
assert are_values_different(type_int, type_none) | ||
def test_diff_values_mixed(): | ||
assert are_values_different(1.0, 1) | ||
assert are_values_different(1.0, "1") | ||
assert are_values_different(1, "1") | ||
assert are_values_different(1, None) | ||
assert are_values_different(np.ndarray([0]), 'hey') | ||
assert not are_values_different(type_none, type_none) | ||
|
||
|
||
@given(st.data()) | ||
def test_diff_values_array(data): | ||
a = data.draw(st.lists(elements=st.integers(min_value=0), min_size=1)) | ||
b = data.draw(st.lists(elements=st.integers(max_value=-1), min_size=1)) | ||
c = data.draw(st.lists(elements=st.floats(min_value=1e8), min_size=1)) | ||
d = data.draw(st.lists(elements=st.floats(max_value=-1e8), min_size=1)) | ||
# TODO: Figure out a way to include 0 in lists (arrays) | ||
|
||
assert are_values_different(a, b) | ||
assert are_values_different(c, d) | ||
assert not are_values_different(a, a) | ||
assert not are_values_different(None, None) | ||
|
||
|
||
def test_diff_values_array(): | ||
from numpy import NaN, array, inf | ||
a_int = array([1, 2]) | ||
a_float = a_int.astype(float) | ||
|
||
assert are_values_different(a_int, a_float) | ||
assert are_values_different(a_int, a_int, a_float) | ||
assert are_values_different(np.arange(3), np.arange(1, 4)) | ||
assert are_values_different(np.arange(3), np.arange(4)) | ||
assert are_values_different(np.arange(4), np.arange(4).reshape((2, 2))) | ||
# no broadcasting should kick in - shape difference | ||
assert are_values_different(array([1]), array([1, 1])) | ||
assert not are_values_different(a_int, a_int) | ||
assert not are_values_different(a_float, a_float) | ||
|
||
# NaNs - we consider them "the same" for the purpose of these comparisons | ||
assert not are_values_different(NaN, NaN) | ||
assert not are_values_different(NaN, NaN, NaN) | ||
assert are_values_different(NaN, NaN, 1) | ||
assert are_values_different(1, NaN, NaN) | ||
assert not are_values_different(array([NaN, NaN]), array([NaN, NaN])) | ||
assert not are_values_different(array([NaN, NaN]), array([NaN, NaN]), array([NaN, NaN])) | ||
assert not are_values_different(array([NaN, 1]), array([NaN, 1])) | ||
assert are_values_different(array([NaN, NaN]), array([NaN, 1])) | ||
assert are_values_different(array([0, NaN]), array([NaN, 0])) | ||
# and some inf should not be a problem | ||
assert not are_values_different(array([0, inf]), array([0, inf])) | ||
assert are_values_different(array([0, inf]), array([inf, 0])) |
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.
Numpy prefers you to use
np.nan
. I don't know if this means they plan to remove the synonyms in the future or if it's just a style thing. I'd go with their recommendation, though.Also appears in the test file.