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

[AL-2335] Fixes to .data to make returned results identical to python #2457

Merged
merged 19 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions deeplake/core/dataset/deeplake_query_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __getitem__(
"Indexing by integer in a for loop, like `for i in range(len(ds)): ... ds[i]` can be quite slow. Use `for i, sample in enumerate(ds)` instead."
)
ret = DeepLakeQueryDataset(
deeplake_ds=self.deeplake_ds,
deeplake_ds=self.deeplake_ds[item],
indra_ds=self.indra_ds[item],
)
else:
Expand Down Expand Up @@ -305,7 +305,7 @@ def copy(self, *args, **kwargs):
)

def __del__(self):
self.indra_ds = None
pass

def random_split(self, lengths: Sequence[Union[int, float]]):
if math.isclose(sum(lengths), 1) and sum(lengths) <= 1:
Expand Down
24 changes: 21 additions & 3 deletions deeplake/core/dataset/deeplake_query_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ def numpy(

def text(self, fetch_chunks: bool = False):
"""Return text data. Only applicable for tensors with 'text' base htype."""
if len(self.indra_tensor) == 1:
if self.ndim == 1:
return self.indra_tensor.bytes().decode()
return list(
self.indra_tensor[i].bytes().decode() for i in range(len(self.indra_tensor))
)

def dict(self, fetch_chunks: bool = False):
"""Return json data. Only applicable for tensors with 'json' base htype."""
if len(self.indra_tensor) == 1:
if self.ndim == 1:
return json.loads(self.indra_tensor.bytes().decode())
return list(
json.loads(self.indra_tensor[i].bytes().decode())
Expand Down Expand Up @@ -127,6 +127,17 @@ def min_shape(self):

@property
def shape(self):
result = ()
index_0 = self.deeplake_tensor.index.values[0]
if self.indra_tensor.min_shape == self.indra_tensor.max_shape:
if index_0.is_trivial():
return self.indra_tensor.shape_interval
else:
return self.indra_tensor.shape_interval[1:]

if index_0.subscriptable():
return (len(self.indra_tensor), *self.indra_tensor.shape) # type: ignore

return self.indra_tensor.shape

@property
Expand All @@ -139,7 +150,14 @@ def shape_interval(self):

@property
def ndim(self):
return len(self.max_shape)
ndim = len(self.indra_tensor.min_shape) + 1
if self.indra_tensor.is_sequence:
ndim += 1
if self.deeplake_tensor.index:
for idx in self.deeplake_tensor.index.values:
if not idx.subscriptable():
ndim -= 1
return ndim

@property
def meta(self):
Expand Down
Loading
Loading