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

Vocab.to_disk exclude doesn't respect vectors #11833 #11834

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: black
language_version: python3.7
additional_dependencies: ['click==8.0.4']
- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
svlandeg marked this conversation as resolved.
Show resolved Hide resolved
rev: 5.0.4
hooks:
- id: flake8
Expand Down
21 changes: 21 additions & 0 deletions spacy/tests/vocab_vectors/test_vocab_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os

import pytest
from spacy.attrs import IS_ALPHA, LEMMA, ORTH
from spacy.lang.en import English
from spacy.parts_of_speech import NOUN, VERB
from spacy.vocab import Vocab

from ..util import make_tempdir


@pytest.mark.issue(1868)
def test_issue1868():
Expand Down Expand Up @@ -59,3 +64,19 @@ def test_vocab_api_contains(en_vocab, text):
def test_vocab_writing_system(en_vocab):
assert en_vocab.writing_system["direction"] == "ltr"
assert en_vocab.writing_system["has_case"] is True


def test_to_disk():
nlp = English()
with make_tempdir() as d:
nlp.vocab.to_disk(d)
assert "vectors" in os.listdir(d)
assert "lookups.bin" in os.listdir(d)


def test_to_disk_exclude():
nlp = English()
with make_tempdir() as d:
nlp.vocab.to_disk(d, exclude=("vectors", "lookups"))
assert "vectors" not in os.listdir(d)
assert "lookups.bin" not in os.listdir(d)
4 changes: 2 additions & 2 deletions spacy/vocab.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ cdef class Vocab:
setters = ["strings", "vectors"]
if "strings" not in exclude:
self.strings.to_disk(path / "strings.json")
if "vectors" not in "exclude":
if "vectors" not in exclude:
self.vectors.to_disk(path, exclude=["strings"])
if "lookups" not in "exclude":
if "lookups" not in exclude:
self.lookups.to_disk(path)

def from_disk(self, path, *, exclude=tuple()):
Expand Down