From ea611b43c15d3592f1fa844baf872b91935fb821 Mon Sep 17 00:00:00 2001 From: Rupal Sharma <39291744+rsdel2007@users.noreply.github.com> Date: Thu, 17 Jan 2019 09:37:35 +0530 Subject: [PATCH] Replace `open()` by `smart_open()` in `gensim.models.fasttext._load_fasttext_format` (#2335) * replaced open by smart_open * updated smart_open() version * updated smart_open() version --- gensim/models/fasttext.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gensim/models/fasttext.py b/gensim/models/fasttext.py index 7bf58dd5a0..6cdad26fd0 100644 --- a/gensim/models/fasttext.py +++ b/gensim/models/fasttext.py @@ -93,13 +93,13 @@ from numpy import ones, vstack, float32 as REAL, sum as np_sum import six -# TODO use smart_open again when https://github.com/RaRe-Technologies/smart_open/issues/207 will be fixed import gensim.models._fasttext_bin from gensim.models.word2vec import Word2VecVocab, Word2VecTrainables, train_sg_pair, train_cbow_pair from gensim.models.keyedvectors import FastTextKeyedVectors from gensim.models.base_any2vec import BaseWordEmbeddingsModel from gensim.models.utils_any2vec import _compute_ngrams, _ft_hash, _ft_hash_broken +from smart_open import smart_open from gensim.utils import deprecated, call_on_class_only @@ -979,7 +979,7 @@ def _load_fasttext_format(model_file, encoding='utf-8'): """ if not model_file.endswith('.bin'): model_file += '.bin' - with open(model_file, 'rb') as fin: + with smart_open(model_file, 'rb') as fin: m = gensim.models._fasttext_bin.load(fin, encoding=encoding) model = FastText( diff --git a/setup.py b/setup.py index 3e55f387c9..4902dc2198 100644 --- a/setup.py +++ b/setup.py @@ -347,7 +347,7 @@ def finalize_options(self): 'numpy >= 1.11.3', 'scipy >= 0.18.1', 'six >= 1.5.0', - 'smart_open >= 1.2.1', + 'smart_open >= 1.7.0', ], tests_require=linux_testenv, extras_require={