Skip to content

Commit

Permalink
Allow virtual tensors .data to use indra_ts.numpy as fallback. (#2873)
Browse files Browse the repository at this point in the history
* Update bugout token

* Allow text and dict apis to fallback to .numpy().

* Fixed 1dim case.
  • Loading branch information
khustup2 committed Jun 13, 2024
1 parent 31959f2 commit 8b27518
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
36 changes: 24 additions & 12 deletions deeplake/core/dataset/indra_tensor_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,33 @@ def numpy(

def text(self, fetch_chunks: bool = False):
"""Return text data. Only applicable for tensors with 'text' base htype."""
bs = self.indra_tensor.bytes()
if self.ndim == 1:
return bs.decode()
if isinstance(bs, bytes):
return [bs.decode()]
return list(b.decode() for b in bs)
try:
bs = self.indra_tensor.bytes()
if self.ndim == 1:
return bs.decode()
if isinstance(bs, bytes):
return [bs.decode()]
return list(b.decode() for b in bs)
except Exception as e:
bs = self.indra_tensor.numpy(aslist=True)
if self.ndim == 1:
return bs[0]
return list(b[0] for b in bs)

def dict(self, fetch_chunks: bool = False):
"""Return json data. Only applicable for tensors with 'json' base htype."""
bs = self.indra_tensor.bytes()
if self.ndim == 1:
return json.loads(bs.decode())
if isinstance(bs, bytes):
return [json.loads(bs.decode())]
return list(json.loads(b.decode()) for b in self.indra_tensor.bytes())
try:
bs = self.indra_tensor.bytes()
if self.ndim == 1:
return json.loads(bs.decode())
if isinstance(bs, bytes):
return [json.loads(bs.decode())]
return list(json.loads(b.decode()) for b in self.indra_tensor.bytes())
except Exception as e:
bs = self.indra_tensor.numpy(aslist=True)
if self.ndim == 1:
return bs[0]
return list(b[0] for b in bs)

@property
def dtype(self):
Expand Down
2 changes: 1 addition & 1 deletion deeplake/util/bugout_token.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BUGOUT_TOKEN = "f7176d62-73fa-4ecc-b24d-624364bddcb0"
BUGOUT_TOKEN = "0095ccd3-7ff0-41b9-b031-f4eb58f00906"

0 comments on commit 8b27518

Please sign in to comment.