Skip to content

Commit

Permalink
Use new smart_open compression parameter instead of ignore_ext when p…
Browse files Browse the repository at this point in the history
…ossible

Keep compatibility with old versions of smart_open just in case.

1.8.1 is required by the deps, 5.1.0 introduced the compression parameter,
6.0.0 dropped the ignore_ext parameter.
  • Loading branch information
pabs3 committed Mar 18, 2023
1 parent f87e59a commit cd9920b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docs/src/gallery/howtos/run_doc2vec_imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,20 @@ def download_dataset(url='http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v
return fname

# Download the file to local storage first.
with smart_open.open(url, "rb", ignore_ext=True) as fin:
with smart_open.open(fname, 'wb', ignore_ext=True) as fout:
try:
kwargs = { 'compression': smart_open.compression.NO_COMPRESSION }
fin = smart_open.open(url, "rb", **kwargs)
except (AttributeError, TypeError):
kwargs = { 'ignore_ext': True }
fin = smart_open.open(url, "rb", **kwargs)
if fin:
with smart_open.open(fname, 'wb', **kwargs) as fout:
while True:
buf = fin.read(io.DEFAULT_BUFFER_SIZE)
if not buf:
break
fout.write(buf)
fin.close()

return fname

Expand Down

0 comments on commit cd9920b

Please sign in to comment.