-
-
Notifications
You must be signed in to change notification settings - Fork 11k
TST: test_tofile_fromfile now uses initialized memory #12330
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
Conversation
@tylerjereddy sometimes I feel like I work for the CIs.... |
ci/circleci complains about using |
I think the debian archives are just down http://deb.debian.org/debian |
Can you link to such an issue? |
NumPy shippable history: https://app.shippable.com/github/numpy/numpy/dashboard/history in particular: https://app.shippable.com/github/numpy/numpy/runs/1301/summary/console |
It's not obvious to me that the failure is caused by the backport - it might be that we actually have a real problem on python 2, but our tests that expose it happen to use pathlib. If nothing else, I was trying to add explicit backport support in #12157, so it's nice to have CI that tests it somewhere. It's pretty unfortunate that the CI output is truncated to the point of not actually showing the diff. I'd prefer that we work out why the test is failing rather than finding an easy way to disable it. |
Agree with @eric-wieser that it would be good to understand why there is the failure. The fact that it is not reliably repeatable is a complication there, but many of us have Python 2.7 available, so it might be good to test. I would also be inclined to try pathlib2 if that is better maintained. What do we need to do to test, just install a backport? |
If What would the logic look like if you try to support if sys.version_info[0] >= 3:
from pathlib import Path, PurePath
else:
try:
from pathlib2 import Path, PurePath
except ImportError:
try:
from pathlib import Path, PurePath # <- inconsistent behaviour expected?
except ImportError:
Path = PurePath = None |
@hmaarrfk I think the backport behavior is to just automagically show-up in the namespace where the Python 3 module normally is, so if it is a truly reliable backport then you don't need conditionals. I've noted the feedback requesting investigation of the issue -- I'll try to take a look tomorrow. |
nevermindis it because origin pos is never set?
nevermind:
|
@tylerjereddy In fact, this test failed at least once when the above mentioned PR was still open (#11348 (comment)). I thought it was a temporary issue with Shippable. I also doubt that this has anything to do with pathlib on Python2. |
Yeah, I'm leaning towards |
The test will pass if I use assert_allclose for the first two fields, and the original assert_array_equal for the third field |
Perhaps ARMv8 is prone to slightly different floating pulls / precision issues with empty() random picks and / or the comparison of said picks |
It might honestly be that an In [3]: np.nan == np.nan
Out[3]: False |
From the |
39394a4
to
d4a11bf
Compare
oooohhh shippable is running aarch64. Does it have a software FPU or hardware FPU? |
I've updated this PR to use This fixes the comparison in my own local tests anyway--the full contents of the The super-small @hmaarrfk It is proper ARMv8 hardware instead of emulation at the software level, if that is what you are asking me. I don't know if that is a sufficient explanation for the different floating point draws / comparison susceptibilities, but I think using |
I guess it kinda makes sense. What I don't understand is if Re: hard-fp soft-fp, yes that is what I was asking. I've run into peculiarities of soft-fp before not raising errors or only partiallialy implementing IEEE standards. 1E-309 is a denormal number. I wonder if AARM64 implements comparison for them correctly. |
It is totally the import numpy as np
from numpy.testing import assert_array_equal
a = np.zeros(1, dtype='f8,f8')
a[0] = (np.nan, 0)
assert_array_equal(a, a) ---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-6-96868a4fad08> in <module>
----> 1 assert_array_equal(a, a)
/home/mark/git/numpy/numpy/testing/_private/utils.py in assert_array_equal(x, y, err_msg, verbose)
871 __tracebackhide__ = True # Hide traceback for py.test
872 assert_array_compare(operator.__eq__, x, y, err_msg=err_msg,
--> 873 verbose=verbose, header='Arrays are not equal')
874
875
/home/mark/git/numpy/numpy/testing/_private/utils.py in assert_array_compare(comparison, x, y, err_msg, verbose, header, precision, equal_nan, equal_inf)
795 verbose=verbose, header=header,
796 names=('x', 'y'), precision=precision)
--> 797 raise AssertionError(msg)
798 except ValueError:
799 import traceback
AssertionError:
Arrays are not equal
(mismatch 100.0%)
x: array([(nan, 0.)], dtype=[('f0', '<f8'), ('f1', '<f8')])
y: array([(nan, 0.)], dtype=[('f0', '<f8'), ('f1', '<f8')]) testing patch to add
|
Using |
@hmaarrfk Right you are I guess. I think the docstring is perhaps a bit confusing since there's some implication of handling nans appropriately there. Still, maybe not entirely inaccurate to categorize as a floating point issue of some sort. |
I think the line I think this should probably be considered a bug in structured arrays, or at least how |
numpy/core/tests/test_records.py
Outdated
assert_array_equal(x, a) | ||
# check numeric fields within a reasonable | ||
# floating point precision match | ||
assert_allclose(x['f0'], a['f0']) |
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.
Maybe just use assert_array_equal
here. seems to work in the failer I showed.
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.
As long as there's a good reason for that with floating point numbers -- we don't want to check within i.e., 1e-7 precision, we want an "exact" match?
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.
Yes. Serializing to and from a file should yield exact results. We are dumping the bits right? At least I use tofile that way.
In the past, @seberg has made an effort to remove all uses of |
Might be worth opening an issue about that - that seems inconsistent.
Wait till you try using |
d4a11bf
to
f95d197
Compare
Revised based on above comments |
numpy/core/tests/test_records.py
Outdated
@@ -332,7 +332,8 @@ class TestPathUsage(object): | |||
def test_tofile_fromfile(self): | |||
with temppath(suffix='.bin') as path: | |||
path = Path(path) | |||
a = np.empty(10, dtype='f8,i4,a5') | |||
np.random.seed(123) | |||
a = np.random.rand(10).astype('f8,i4,a5') | |||
a[5] = (0.5,10,'abcde') | |||
a.newbyteorder('<') |
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.
AFAICT, newbyteorder
doesn't change anything about a
, and I'm not clear about the purpose of setting a[5]
.
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.
newbyteorder
returns a new array. I think it can be omitted and the read should default to native order. Reversing the order of the original could also lead to problematic floats.
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.
I've revised to remove the byte ordering stuff.
The purpose of setting a[5]
might be to put some more "interesting" data into the array for the purpose of the roundtrip--if empty or random put a bunch of zeros in there I suppose one might argue it is a slightly less thorough check than i.e., heterogeneous data. Indeed, with my change, the integer field becomes all zero before that I think, because of the casting.
But that's just speculation -- I didn't write the original test of course.
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.
I didn't write the original test of course.
Yeah, the original tests seems more a test of records than path :)
* replaced usage of np.empty() in the unit test at TestPathUsage.test_tofile_fromfile with a pinned random seed array * the usage of np.empty() was causing stochastic unit test failures on ARMv8 architecture in both Python 2.7 and 3.7.
f95d197
to
9fe2f4f
Compare
Thanks Tyler. |
Try removing
pathlib
from Shippable CI config since apparently no other NumPy CI config uses this, it is apparently prone to causing issues, and depending on the backport maintenance of a Python 3 standard library module may be a bad idea anyway.An alternative may be to switch to the newer
pathlib2
2.x backport, but I don't think we've done that for any other CI either.Maybe good to check the test skip counts for shippable in this PR -- I think for 2.x quite a few more show up without pathlib so that was my original reasoning for using it.