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

fix joblib.load from stream #1167

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

PetroFrolov
Copy link

@PetroFrolov PetroFrolov commented Mar 23, 2021

I founded an issue when loading data from stream.
Code example

>>> import numpy as np
>>> a = np.array([1, 2, 3])
>>> b = np.array([3, 4, 5])
>>>
>>> import io
>>> import joblib
>>> buf = io.BytesIO()
>>>
>>> joblib.dump(a, buf)
>>> joblib.dump(b, buf)
>>>
>>> buf.seek(0)
0
>>> joblib.load(buf)
array([1, 2, 3])
>>> joblib.load(buf)
array([1, 2, 3])
>>>

VS

>>> import numpy as np
>>> a = np.array([1, 2, 3])
>>> b = np.array([3, 4, 5])
>>> 
>>> import joblib
>>> with open('1.bin', 'wb') as fd:
...     joblib.dump(a, fd)
...     joblib.dump(b, fd)
... 
>>> with open('1.bin', 'rb') as fd:
...     joblib.load(fd)
...     joblib.load(fd)
... 
array([1, 2, 3])
array([3, 4, 5])

My patch will fix it

@codecov
Copy link

codecov bot commented Mar 23, 2021

Codecov Report

Merging #1167 (cbcb397) into master (457d2c8) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1167      +/-   ##
==========================================
+ Coverage   94.48%   94.57%   +0.08%     
==========================================
  Files          47       47              
  Lines        6997     7000       +3     
==========================================
+ Hits         6611     6620       +9     
+ Misses        386      380       -6     
Impacted Files Coverage Δ
joblib/numpy_pickle_utils.py 92.77% <100.00%> (+0.08%) ⬆️
joblib/test/test_numpy_pickle.py 93.38% <100.00%> (+0.02%) ⬆️
joblib/_parallel_backends.py 94.92% <0.00%> (+1.17%) ⬆️
joblib/test/testutils.py 100.00% <0.00%> (+50.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 457d2c8...cbcb397. Read the comment docs.

Copy link
Contributor

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PetroFrolov,

Thank you for your pull request.

Can you add your first snippet as a non-regression test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants