From 03cfb2d2f4afbcc96f99757010ce3263cbc28ebd Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Mon, 5 Oct 2020 09:33:05 +0200 Subject: [PATCH] Always serialize lookups and vectors to disk --- spacy/lookups.py | 13 ++++++------- spacy/vocab.pyx | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/spacy/lookups.py b/spacy/lookups.py index fb5e3d748..133cb0672 100644 --- a/spacy/lookups.py +++ b/spacy/lookups.py @@ -289,13 +289,12 @@ class Lookups: DOCS: https://nightly.spacy.io/api/lookups#to_disk """ - if len(self._tables): - path = ensure_path(path) - if not path.exists(): - path.mkdir() - filepath = path / filename - with filepath.open("wb") as file_: - file_.write(self.to_bytes()) + path = ensure_path(path) + if not path.exists(): + path.mkdir() + filepath = path / filename + with filepath.open("wb") as file_: + file_.write(self.to_bytes()) def from_disk( self, path: Union[str, Path], filename: str = "lookups.bin", **kwargs diff --git a/spacy/vocab.pyx b/spacy/vocab.pyx index a22f12c65..93918250b 100644 --- a/spacy/vocab.pyx +++ b/spacy/vocab.pyx @@ -445,9 +445,9 @@ cdef class Vocab: setters = ["strings", "vectors"] if "strings" not in exclude: self.strings.to_disk(path / "strings.json") - if "vectors" not in "exclude" and self.vectors is not None: + if "vectors" not in "exclude": self.vectors.to_disk(path) - if "lookups" not in "exclude" and self.lookups is not None: + if "lookups" not in "exclude": self.lookups.to_disk(path) def from_disk(self, path, *, exclude=tuple()):