Repository: activeloopai/deeplake

Issue:
Video Tensor cannot be read back after appending numpy array of raw video
# Issue description

I create a new local deeplake dataset, create a tensor, and then append to/extend this tensor (issue is the same with both methods).  When I then try to access the data I just appended, this raises an issue.
`read_sample() got an unexpected keyword argument 'sub_index'`
`ReadSampleFromChunkError: Unable to read sample from chunk 'videos/chunks/d55711f409b649b7'.`
This is frustrating me quite a bit because I only created the numpy array from a number of `.avi` files to be able to resize the videos, something that I could not figure out how to do with deeplake.  I was previously able to easily create and append directly from `.avi` files and now I cannot figure out how to proceed.


# Reproducing code

```
ds_path = '/some/path/'
ds = deeplake.empty(dlgn_ds_path, overwrite=True)

with ds:
    ds.create_tensor('videos', htype='video'. compression=None)

vids = np.zeros((dataset_size, frames, height, width))

with ds:
    ds.videos.extend(vids)

ds.videos[0].data()
```

# Error message:
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~/.local/lib/python3.9/site-packages/deeplake/core/chunk/base_chunk.py:627, in catch_chunk_read_error.<locals>.wrapper(self, *args, **kwargs)
    626 try:
--> 627     return fn(self, *args, **kwargs)
    628 except EmptyTensorError:

TypeError: read_sample() got an unexpected keyword argument 'sub_index'

The above exception was the direct cause of the following exception:

ReadSampleFromChunkError                  Traceback (most recent call last)
File ~/.local/lib/python3.9/site-packages/deeplake/core/chunk_engine.py:1989, in ChunkEngine._numpy(self, index, aslist, use_data_cache, fetch_chunks, pad_tensor)
   1988 try:
-> 1989     sample = self.get_single_sample(
   1990         global_sample_index,
   1991         index,
   1992         fetch_chunks=fetch_chunks,
   1993         pad_tensor=pad_tensor,
   1994     )
   1995 except GetChunkError as e:

File ~/.local/lib/python3.9/site-packages/deeplake/core/chunk_engine.py:1931, in ChunkEngine.get_single_sample(self, global_sample_index, index, fetch_chunks, pad_tensor, decompress)
   1930 if not self._is_tiled_sample(global_sample_index):
-> 1931     sample = self.get_non_tiled_sample(
   1932         global_sample_index,
   1933         index,
   1934         fetch_chunks=fetch_chunks,
   1935         decompress=decompress,
   1936     )
   1937 elif len(index.values) == 1:

File ~/.local/lib/python3.9/site-packages/deeplake/core/chunk_engine.py:1882, in ChunkEngine.get_non_tiled_sample(self, global_sample_index, index, fetch_chunks, decompress)
   1881 if self.is_video:
-> 1882     return self.get_video_sample(
   1883         global_sample_index, index, decompress=decompress
   1884     )
   1885 return self.get_basic_sample(
   1886     global_sample_index, index, fetch_chunks=fetch_chunks, decompress=decompress
   1887 )

File ~/.local/lib/python3.9/site-packages/deeplake/core/chunk_engine.py:1802, in ChunkEngine.get_video_sample(self, global_sample_index, index, decompress)
   1801 sub_index = index.values[1].value if len(index.values) > 1 else None  # type: ignore
-> 1802 sample = chunk.read_sample(
   1803     local_sample_index,
   1804     sub_index=sub_index,
   1805     stream=stream,
   1806     decompress=decompress,
   1807 )
   1808 if decompress:

File ~/.local/lib/python3.9/site-packages/deeplake/core/chunk/base_chunk.py:631, in catch_chunk_read_error.<locals>.wrapper(self, *args, **kwargs)
    630 except Exception as e:
--> 631     raise ReadSampleFromChunkError(self.key) from e

ReadSampleFromChunkError: Unable to read sample from chunk 'videos/chunks/d55711f409b649b7'.

The above exception was the direct cause of the following exception:

ReadSampleFromChunkError                  Traceback (most recent call last)
Cell In[32], line 1
----> 1 ds.videos[0].numpy()

File ~/.local/lib/python3.9/site-packages/deeplake/core/tensor.py:788, in Tensor.numpy(self, aslist, fetch_chunks)
    763 def numpy(
    764     self, aslist=False, fetch_chunks=False
    765 ) -> Union[np.ndarray, List[np.ndarray]]:
    766     """Computes the contents of the tensor in numpy format.
    767 
    768     Args:
   (...)
    786         For tensors of htype ``polygon``, aslist is always ``True``.
    787     """
--> 788     ret = self.chunk_engine.numpy(
    789         self.index,
    790         aslist=aslist,
    791         fetch_chunks=fetch_chunks or self.is_iteration,
    792         pad_tensor=self.pad_tensor,
    793     )
    794     if self.htype == "point_cloud":  # TODO: refactor
    795         if isinstance(ret, list):

File ~/.local/lib/python3.9/site-packages/deeplake/core/chunk_engine.py:1792, in ChunkEngine.numpy(self, index, aslist, use_data_cache, fetch_chunks, pad_tensor)
   1790 self.check_link_ready()
   1791 fetch_chunks = fetch_chunks or self._get_full_chunk(index)
-> 1792 return (self._sequence_numpy if self.is_sequence else self._numpy)(
   1793     index, aslist, use_data_cache, fetch_chunks, pad_tensor
   1794 )

File ~/.local/lib/python3.9/site-packages/deeplake/core/chunk_engine.py:2000, in ChunkEngine._numpy(self, index, aslist, use_data_cache, fetch_chunks, pad_tensor)
   1996     raise GetChunkError(
   1997         e.chunk_key, global_sample_index, self.name
   1998     ) from e
   1999 except ReadSampleFromChunkError as e:
-> 2000     raise ReadSampleFromChunkError(
   2001         e.chunk_key, global_sample_index, self.name
   2002     ) from e
   2003 except GetDataFromLinkError as e:
   2004     raise GetDataFromLinkError(
   2005         e.link, global_sample_index, self.name
   2006     ) from e

ReadSampleFromChunkError: Unable to read sample at index 0 from chunk 'videos/chunks/d55711f409b649b7' in tensor videos.
```


Discussion:
Hey @nwcimaszewski, sorry about the late update, but we've found the bug that's causing this issue. Thanks a lot for reporting this! We will do our best to release the fix as soon as possible.

Resolving patch:
diff --git a/deeplake/core/chunk/uncompressed_chunk.py b/deeplake/core/chunk/uncompressed_chunk.py
--- a/deeplake/core/chunk/uncompressed_chunk.py
+++ b/deeplake/core/chunk/uncompressed_chunk.py
@@ -190,6 +190,8 @@ def read_sample(
         local_index: int,
         cast: bool = True,
         copy: bool = False,
+        sub_index: Optional[Union[int, slice]] = None,
+        stream: bool = False,
         decompress: bool = True,
         is_tile: bool = False,
     ):
diff --git a/deeplake/core/vectorstore/vector_search/indra/search_algorithm.py b/deeplake/core/vectorstore/vector_search/indra/search_algorithm.py
--- a/deeplake/core/vectorstore/vector_search/indra/search_algorithm.py
+++ b/deeplake/core/vectorstore/vector_search/indra/search_algorithm.py
@@ -41,6 +41,7 @@ def search(
     """
     try:
         from indra import api  # type: ignore
+
         INDRA_INSTALLED = True
     except ImportError:
         INDRA_INSTALLED = False


Test patch:
diff --git a/deeplake/api/tests/test_video.py b/deeplake/api/tests/test_video.py
--- a/deeplake/api/tests/test_video.py
+++ b/deeplake/api/tests/test_video.py
@@ -26,7 +26,10 @@ def test_video(local_ds, compression, video_paths):
             elif compression == "mkv":
                 assert sample.shape == (399, 360, 640, 3)
             elif compression == "avi":
-                assert sample.shape == (901, 270, 480, 3)
+                if i == 0:
+                    assert sample.shape == (901, 270, 480, 3)
+                elif i == 1:
+                    assert sample.shape == (3, 480, 852, 3)
         assert sample.shape[-1] == 3
         with local_ds:
             for _ in range(5):
@@ -199,3 +202,14 @@ def test_linked_video_timestamps(local_ds):
         ds.videos[0, 5:10].timestamps == np.array(
             [0.04170833, 0.08341666, 0.125125, 0.16683333, 0.20854166]
         )
+
+
+def test_uncompressed_video_bug(local_path, video_paths):
+    with deeplake.empty(local_path, overwrite=True) as ds:
+        ds.create_tensor("video", htype="video", sample_compression=None)
+        ds.video.append(deeplake.read(video_paths["avi"][1]))
+
+    assert ds.video[0].numpy().shape == (3, 480, 852, 3)
+
+    with deeplake.load(local_path) as ds:
+        assert ds.video[0].numpy().shape == (3, 480, 852, 3)
diff --git a/deeplake/tests/dummy_data/video/tinyavi.avi b/deeplake/tests/dummy_data/video/tinyavi.avi
new file mode 100644
Binary files /dev/null and b/deeplake/tests/dummy_data/video/tinyavi.avi differ
diff --git a/deeplake/tests/path_fixtures.py b/deeplake/tests/path_fixtures.py
--- a/deeplake/tests/path_fixtures.py
+++ b/deeplake/tests/path_fixtures.py
@@ -541,7 +541,7 @@ def video_paths():
     paths = {
         "mp4": ["samplemp4.mp4"],
         "mkv": ["samplemkv.mkv"],
-        "avi": ["sampleavi.avi"],
+        "avi": ["sampleavi.avi", "tinyavi.avi"],
     }
 
     parent = get_dummy_data_path("video")