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

Type documentation fixes for Doc #13187

Merged
merged 7 commits into from
Dec 18, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions spacy/tokens/doc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Doc:
vector: Optional[Floats1d] = ...,
alignment_mode: str = ...,
span_id: Union[int, str] = ...,
) -> Span: ...
) -> Optional[Span]: ...
def similarity(self, other: Union[Doc, Span, Token, Lexeme]) -> float: ...
@property
def has_vector(self) -> bool: ...
Expand Down Expand Up @@ -179,15 +179,13 @@ class Doc:
self, path: Union[str, Path], *, exclude: Iterable[str] = ...
) -> None: ...
def from_disk(
self, path: Union[str, Path], *, exclude: Union[List[str], Tuple[str]] = ...
) -> Doc: ...
def to_bytes(self, *, exclude: Union[List[str], Tuple[str]] = ...) -> bytes: ...
def from_bytes(
self, bytes_data: bytes, *, exclude: Union[List[str], Tuple[str]] = ...
self, path: Union[str, Path], *, exclude: Iterable[str] = ...
) -> Doc: ...
def to_dict(self, *, exclude: Union[List[str], Tuple[str]] = ...) -> bytes: ...
def to_bytes(self, *, exclude: Iterable[str] = ...) -> bytes: ...
def from_bytes(self, bytes_data: bytes, *, exclude: Iterable[str] = ...) -> Doc: ...
def to_dict(self, *, exclude: Iterable[str] = ...) -> Dict[str, Any]: ...
def from_dict(
self, msg: bytes, *, exclude: Union[List[str], Tuple[str]] = ...
self, msg: Dict[str, Any], *, exclude: Iterable[str] = ...
) -> Doc: ...
def extend_tensor(self, tensor: Floats2d) -> None: ...
def retokenize(self) -> Retokenizer: ...
Expand Down
21 changes: 8 additions & 13 deletions spacy/tokens/doc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ cdef class Doc:

path (str / Path): A path to a directory. Paths may be either
strings or `Path`-like objects.
exclude (list): String names of serialization fields to exclude.
exclude (Iterable[str]): String names of serialization fields to exclude.
RETURNS (Doc): The modified `Doc` object.

DOCS: https://spacy.io/api/doc#from_disk
Expand All @@ -1339,7 +1339,7 @@ cdef class Doc:
def to_bytes(self, *, exclude=tuple()):
"""Serialize, i.e. export the document contents to a binary string.

exclude (list): String names of serialization fields to exclude.
exclude (Iterable[str]): String names of serialization fields to exclude.
RETURNS (bytes): A losslessly serialized copy of the `Doc`, including
all annotations.

Expand All @@ -1351,7 +1351,7 @@ cdef class Doc:
"""Deserialize, i.e. import the document contents from a binary string.

data (bytes): The string to load from.
exclude (list): String names of serialization fields to exclude.
exclude (Iterable[str]): String names of serialization fields to exclude.
RETURNS (Doc): Itself.

DOCS: https://spacy.io/api/doc#from_bytes
Expand All @@ -1361,11 +1361,8 @@ cdef class Doc:
def to_dict(self, *, exclude=tuple()):
"""Export the document contents to a dictionary for serialization.

exclude (list): String names of serialization fields to exclude.
RETURNS (bytes): A losslessly serialized copy of the `Doc`, including
all annotations.

DOCS: https://spacy.io/api/doc#to_bytes
adrianeboyd marked this conversation as resolved.
Show resolved Hide resolved
exclude (Iterable[str]): String names of serialization fields to exclude.
RETURNS (Dict[str, Any]): A dictionary representation of the `Doc`
"""
array_head = Doc._get_array_attrs()
strings = set()
Expand Down Expand Up @@ -1411,13 +1408,11 @@ cdef class Doc:
return util.to_dict(serializers, exclude)

def from_dict(self, msg, *, exclude=tuple()):
"""Deserialize, i.e. import the document contents from a binary string.
"""Deserialize the document contents from a dictionary representation.

data (bytes): The string to load from.
exclude (list): String names of serialization fields to exclude.
msg (Dict[str, Any]): The dictionary to load from.
exclude (Iterable[str]): String names of serialization fields to exclude.
RETURNS (Doc): Itself.

DOCS: https://spacy.io/api/doc#from_dict
"""
if self.length != 0:
raise ValueError(Errors.E033.format(length=self.length))
Expand Down