Skip to content

Commit

Permalink
feat(document): add document post as sugar (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao authored Apr 19, 2022
1 parent d822fe8 commit 446507d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docarray/array/mixins/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def post(
elif _scheme in ('grpc', 'http', 'ws', 'websocket'):
from jina import Client

c = Client(host=r.hostname)
standardized_host = standardized_host + (f':{_port}' or '')
c = Client(host=standardized_host)
return c.post(
_on,
inputs=self,
Expand Down
6 changes: 6 additions & 0 deletions docarray/document/mixins/sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ def embed(self: 'T', *args, **kwargs) -> 'T':
_tmp = DocumentArray(self)
_tmp.embed(*args, **kwargs)
return self

def post(self: 'T', *args, **kwargs) -> 'T':
from ... import DocumentArray

_tmp = DocumentArray(self)
return _tmp.post(*args, **kwargs)[0]
4 changes: 3 additions & 1 deletion tests/unit/array/mixins/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from docarray import DocumentArray
from docarray import DocumentArray, Document
from docarray.helper import random_port


Expand Down Expand Up @@ -39,6 +39,8 @@ def test_post_with_jinahub(hub_uri):
da = DocumentArray.empty(100)
da.post(hub_uri)

assert isinstance(Document().post(hub_uri), Document)


def test_post_bad_scheme():
da = DocumentArray.empty(100)
Expand Down

0 comments on commit 446507d

Please sign in to comment.