From a2f2bb523db03338fb03bafebfe92e0bf6d91ab6 Mon Sep 17 00:00:00 2001 From: Sami Jaghouar Date: Mon, 14 Nov 2022 11:44:31 +0100 Subject: [PATCH 1/2] refactor: rename base node method Signed-off-by: Sami Jaghouar --- docarray/array/mixins/proto.py | 2 +- docarray/document/base_node.py | 2 +- docarray/document/mixins/proto.py | 4 ++-- docarray/typing/tensor/tensor.py | 4 ++-- docarray/typing/url/any_url.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docarray/array/mixins/proto.py b/docarray/array/mixins/proto.py index a38637f4e6d..895c653329d 100644 --- a/docarray/array/mixins/proto.py +++ b/docarray/array/mixins/proto.py @@ -28,7 +28,7 @@ def to_protobuf(self) -> 'DocumentArrayProto': dap.docs.append(doc.to_protobuf()) return dap - def _to_nested_item_protobuf(self) -> 'NodeProto': + def _to_node_protobuf(self) -> 'NodeProto': """Convert a DocumentArray into a nested item protobuf message. This function should be called when a DocumentArray is nested into another Document that need to be converted into a protobuf diff --git a/docarray/document/base_node.py b/docarray/document/base_node.py index 507511aef56..54f44f4a6cb 100644 --- a/docarray/document/base_node.py +++ b/docarray/document/base_node.py @@ -10,7 +10,7 @@ class BaseNode(ABC): """ @abstractmethod - def _to_nested_item_protobuf(self) -> 'NodeProto': + def _to_node_protobuf(self) -> 'NodeProto': """Convert itself into a nested item protobuf message. This function should be called when the self is nested into another Document that need to be converted into a protobuf diff --git a/docarray/document/mixins/proto.py b/docarray/document/mixins/proto.py index dea1bc13115..923f382d27d 100644 --- a/docarray/document/mixins/proto.py +++ b/docarray/document/mixins/proto.py @@ -61,7 +61,7 @@ def to_protobuf(self) -> 'DocumentProto': for field, value in self: try: if isinstance(value, BaseNode): - nested_item = value._to_nested_item_protobuf() + nested_item = value._to_node_protobuf() elif type(value) is str: nested_item = NodeProto(text=value) @@ -91,7 +91,7 @@ def to_protobuf(self) -> 'DocumentProto': return DocumentProto(data=data) - def _to_nested_item_protobuf(self) -> 'NodeProto': + def _to_node_protobuf(self) -> 'NodeProto': """Convert Document into a nested item protobuf message. This function should be called when the Document is nest into another Document that need to be converted into a protobuf diff --git a/docarray/typing/tensor/tensor.py b/docarray/typing/tensor/tensor.py index cf576ffe3d5..14ee0d63eb0 100644 --- a/docarray/typing/tensor/tensor.py +++ b/docarray/typing/tensor/tensor.py @@ -1,4 +1,4 @@ -from typing import Union, TypeVar, Any, TYPE_CHECKING, Type, cast +from typing import TYPE_CHECKING, Any, Type, TypeVar, Union, cast import numpy as np @@ -40,7 +40,7 @@ def validate( def from_ndarray(cls: Type[T], value: np.ndarray) -> T: return value.view(cls) - def _to_nested_item_protobuf(self: T) -> 'NodeProto': + def _to_node_protobuf(self: T) -> 'NodeProto': """Convert Document into a nested item protobuf message. This function should be called when the Document is nested into another Document that need to be converted into a protobuf diff --git a/docarray/typing/url/any_url.py b/docarray/typing/url/any_url.py index 382a01fca46..93c513c05c8 100644 --- a/docarray/typing/url/any_url.py +++ b/docarray/typing/url/any_url.py @@ -5,7 +5,7 @@ class AnyUrl(BaseAnyUrl, BaseNode): - def _to_nested_item_protobuf(self) -> 'NodeProto': + def _to_node_protobuf(self) -> 'NodeProto': """Convert Document into a nested item protobuf message. This function should be called when the Document is nested into another Document that need to be converted into a protobuf From e514dc9afa95c75af10b91d5a07cf0628f35b834 Mon Sep 17 00:00:00 2001 From: Sami Jaghouar Date: Mon, 14 Nov 2022 11:47:52 +0100 Subject: [PATCH 2/2] refactor: update docstrng Signed-off-by: Sami Jaghouar --- docarray/array/mixins/proto.py | 4 ++-- docarray/document/base_node.py | 4 ++-- docarray/document/mixins/proto.py | 4 ++-- docarray/typing/tensor/tensor.py | 4 ++-- docarray/typing/url/any_url.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docarray/array/mixins/proto.py b/docarray/array/mixins/proto.py index 895c653329d..de9aee858e6 100644 --- a/docarray/array/mixins/proto.py +++ b/docarray/array/mixins/proto.py @@ -28,8 +28,8 @@ def to_protobuf(self) -> 'DocumentArrayProto': dap.docs.append(doc.to_protobuf()) return dap - def _to_node_protobuf(self) -> 'NodeProto': - """Convert a DocumentArray into a nested item protobuf message. + def _to_node_protobuf(self) -> NodeProto: + """Convert a DocumentArray into a NodeProto protobuf message. This function should be called when a DocumentArray is nested into another Document that need to be converted into a protobuf diff --git a/docarray/document/base_node.py b/docarray/document/base_node.py index 54f44f4a6cb..514d6031523 100644 --- a/docarray/document/base_node.py +++ b/docarray/document/base_node.py @@ -10,8 +10,8 @@ class BaseNode(ABC): """ @abstractmethod - def _to_node_protobuf(self) -> 'NodeProto': - """Convert itself into a nested item protobuf message. This function should + def _to_node_protobuf(self) -> NodeProto: + """Convert itself into a NodeProto message. This function should be called when the self is nested into another Document that need to be converted into a protobuf diff --git a/docarray/document/mixins/proto.py b/docarray/document/mixins/proto.py index 923f382d27d..0f4f5fc7a64 100644 --- a/docarray/document/mixins/proto.py +++ b/docarray/document/mixins/proto.py @@ -91,8 +91,8 @@ def to_protobuf(self) -> 'DocumentProto': return DocumentProto(data=data) - def _to_node_protobuf(self) -> 'NodeProto': - """Convert Document into a nested item protobuf message. This function should be + def _to_node_protobuf(self) -> NodeProto: + """Convert Document into a NodeProto protobuf message. This function should be called when the Document is nest into another Document that need to be converted into a protobuf diff --git a/docarray/typing/tensor/tensor.py b/docarray/typing/tensor/tensor.py index 14ee0d63eb0..32e14fb1362 100644 --- a/docarray/typing/tensor/tensor.py +++ b/docarray/typing/tensor/tensor.py @@ -40,8 +40,8 @@ def validate( def from_ndarray(cls: Type[T], value: np.ndarray) -> T: return value.view(cls) - def _to_node_protobuf(self: T) -> 'NodeProto': - """Convert Document into a nested item protobuf message. This function should + def _to_node_protobuf(self: T) -> NodeProto: + """Convert Document into a NodeProto protobuf message. This function should be called when the Document is nested into another Document that need to be converted into a protobuf diff --git a/docarray/typing/url/any_url.py b/docarray/typing/url/any_url.py index 93c513c05c8..c8cf3ed872b 100644 --- a/docarray/typing/url/any_url.py +++ b/docarray/typing/url/any_url.py @@ -5,8 +5,8 @@ class AnyUrl(BaseAnyUrl, BaseNode): - def _to_node_protobuf(self) -> 'NodeProto': - """Convert Document into a nested item protobuf message. This function should + def _to_node_protobuf(self) -> NodeProto: + """Convert Document into a NodeProto protobuf message. This function should be called when the Document is nested into another Document that need to be converted into a protobuf