-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
ENH: Allow reading from buffered stdout using np.fromfile #12324
base: main
Are you sure you want to change the base?
Conversation
Shippable failed with this test:
but I can't seem to find it when i search... |
cd63ae4
to
ac308ce
Compare
Is there a preference between
and
|
ac308ce
to
38d82ab
Compare
38d82ab
to
389505c
Compare
I'd probably opt for passing |
Ok. Any clue where the python 2.7 test is? Seems important... |
|
I've seen that failure on other PRs, but not all, or even all recent, so I don't know what is the cause. It seems inconsistent, only on shippable, and only on Python 2.7. Might try a rebase to see if that fixes it. |
389505c
to
0f3df44
Compare
Sorry my repo was out of sync. How is it even getting in that test? Path should be None..... I rebased, lets see what happens. |
The shippable CI uses |
Thanks @tylerjereddy. Is this considered a bugfix or feature? If it is a feature, then maybe we can just ignore 2.7? |
0f3df44
to
cbe2283
Compare
@charris didn't mean to ignore your comment. Thanks for chiming in. my webpage was out of sync. |
I opened another PR to try to fix the shippable 2.x issue. In that PR & here I see circleci now starting to fail for some reason! |
cbe2283
to
6d038b8
Compare
I can't see the old shippable output, as the link is discarded every time you rebase - so can't help you. Can you link to the failed output next time? Edit: https://app.shippable.com/github/numpy/numpy/runs/1301/1/tests, I assume |
@eric-wieser it seems that shippable is using a backport of pathlib, I didn't know that. Hence the discussion in #12330 |
@eric-wieser adding te comment here since that subthread is annoying. On the line: numpy/numpy/core/include/numpy/npy_3kcompat.h Line 220 in 619926d
It detects an error, but keeps going. Shouldn't it return in the if statement?
|
6d038b8
to
5814870
Compare
I would also like it if a |
5814870
to
1884fa7
Compare
Congrats, you found a bug |
Lol, shippable passed, then I removed some commit noise (whitespace that I had added) and it failed. |
589038d
to
d7767b3
Compare
Thanks @tylerjereddy . This is passing now!!!! |
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.
Only minor nits left.
I don't understand the big picture here - why did we care that the file was buffered before, and why do we care that it's seekable now?
numpy/core/tests/test_longdouble.py
Outdated
'import sys; sys.stdout.write("numpy is not np")'], | ||
stdout=sp.PIPE, bufsize=bufsize) | ||
arr = np.fromfile(p.stdout, dtype=np.uint8, | ||
count=len('numpy is not np')) |
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.
Do you want to read to completion in the test, rather than specify a length? Alternatively, do you want to add some extra characters, and see if p.stdout.read()
returns only the extras?
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.
done.
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'm not sure it will work with unbuffered stdout, but lets see.
numpy/core/tests/test_longdouble.py
Outdated
arr = np.fromfile(p.stdout, dtype=np.uint8, | ||
count=len('numpy is not np')) | ||
assert_array_equal(arr.tostring(), | ||
np.asarray('numpy is not np', dtype='|S')) |
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.
This looks like a weird test. The return type of tostring
(aka tobytes
) is bytes, so I'd compare it against a bytes literal, not against a 0d array
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.
done.
d7767b3
to
3b74a07
Compare
I think we care that it is seekable because on failure it would reset the location of the file. Not really sure though. The comments indicated that they were using the buffered test as a proxy to seekability. |
73047f3
to
538f414
Compare
@eric-wieser It seems that the code that tries to guess how long a file is also uses seek, but doesn't check the Basically multiarraymodule.c should check the output of fp = npy_PyFile_Dup2(file, "rb", &orig_pos);
if (fp == NULL) {
Py_DECREF(file);
return NULL;
}
if (type == NULL) {
type = PyArray_DescrFromType(NPY_DEFAULT_TYPE);
}
ret = PyArray_FromFile(fp, type, (npy_intp) nin, sep); and return a resonable error message telling the user that they must specify In my mind, a patch would include a test that raises an exception when the count parameter isn't provided when trying to read from the stdout buffer. |
a2e78a1
to
482b315
Compare
Thanks eric, seems like there is a serious bug that was found due to the tests you requested. I'll have to keep looking into it. |
482b315
to
f488cc4
Compare
@eric-wieser i'm stumped. Basically, it works in pure python as shown by the tests https://travis-ci.org/numpy/numpy/jobs/453301883#L4540 only 2 "numpy-ic" fail, the two "pythonic" ones pass well. I split the tests so you can do it on your computer by checking out the commit before the mods to the implementation are done. My ultimate goal here would be to make a well tested I couldn't find many tests for |
f488cc4
to
861f30b
Compare
861f30b
to
1973034
Compare
1973034
to
912c9af
Compare
Previously, np.fromfile would check if the object was an object of RawIO. If it was, then it wasn't seekable.
Unfortunately, (at least in python 3) this doesn't work for stdout as it is
buffered
but notseekable
(at least on linux).This fixes that by calling
file.seekable()
Tests are also added to ensure the behaviour lives on.
Fixes #12309
Patch from 2018, before rebase in 2022:
12324_before_rebase.patch.txt