Skip to content

Commit

Permalink
Addressing Sonar-found bugs and code smells. (#2487)
Browse files Browse the repository at this point in the history
* Addressing sonar-found bugs and bad code smells.
Primarily:
- Unused variables
- Missing "Optional" in type definitions
- Use https for test download to avoid sonar complaints

---------

Co-authored-by: Tatevik Hakobyan <83741606+tatevikh@users.noreply.github.com>
Co-authored-by: Fayaz Rahman <fayazrahman4u@gmail.com>
  • Loading branch information
3 people authored Jul 21, 2023
1 parent 44906a6 commit aac3873
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions deeplake/api/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def _reset_and_load(storage, access_method, dataset_kwargs, address, err):
if storage.read_only:
msg = "Cannot reset when loading dataset in read-only mode."
if parent_commit_id:
msg += f" However, you can try loading the previous commit using "
msg += " However, you can try loading the previous commit using "
msg += f"`deeplake.load('{dataset_kwargs.get('path')}@{parent_commit_id}')`."
raise ReadOnlyModeError(msg)
if parent_commit_id is None:
Expand Down Expand Up @@ -1175,7 +1175,7 @@ def deepcopy(
else:
if not isinstance(src, Dataset):
raise TypeError(
f"The specified ``src`` is not an allowed type. Please specify a dataset or a materialized dataset view."
"The specified ``src`` is not an allowed type. Please specify a dataset or a materialized dataset view."
)

if not src.index.is_trivial():
Expand Down
2 changes: 1 addition & 1 deletion deeplake/api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ def test_hub_remote_read_videos(storage, memory_ds):
memory_ds.create_tensor("videos", htype="video", sample_compression="mp4")

video = deeplake.read(
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4",
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4",
)
memory_ds.videos.append(video)
assert memory_ds.videos[0].shape == (361, 720, 1280, 3)
Expand Down
2 changes: 1 addition & 1 deletion deeplake/api/tests/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_video(request, local_ds_generator, create_shape_tensor, verify):
)
for _ in range(3):
sample = deeplake.link(
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"
)
ds.linked_videos.append(sample)

Expand Down
2 changes: 1 addition & 1 deletion deeplake/api/tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_linked_video_timestamps(local_ds):
ds.create_tensor("videos", htype="link[video]", sample_compression="mp4")
ds.videos.append(
deeplake.link(
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4",
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4",
creds_key="ENV",
)
)
Expand Down
4 changes: 2 additions & 2 deletions deeplake/core/chunk_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ def _sequence_length(self):
return

@property
def sequence_encoder(self) -> SequenceEncoder:
def sequence_encoder(self) -> Optional[SequenceEncoder]:
"""Gets the shape encoder from cache, if one is not found it creates a blank encoder.
Raises:
Expand Down Expand Up @@ -2676,7 +2676,7 @@ def shapes(
convert_bad_to_list: bool = True,
):
if len(index) > 1:
raise IndexError(f"`.shapes` only accepts indexing on the primary axis.")
raise IndexError("`.shapes` only accepts indexing on the primary axis.")

index_0 = index.values[0]
num_samples, sample_ndim = self._get_total_samples_and_sample_ndim(index_0)
Expand Down
2 changes: 1 addition & 1 deletion deeplake/core/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3116,7 +3116,7 @@ def get_sample_from_engine(
self[k] = v
except Exception as e2:
raise Exception(
f"Error while attempting to rollback updates"
"Error while attempting to rollback updates"
) from e2
raise e
finally:
Expand Down
4 changes: 2 additions & 2 deletions deeplake/core/vectorstore/test_deeplake_vectorstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_search_basic(local_path, hub_cloud_dev_token):
assert len(data_ce.keys()) == 3 # One for each return_tensors + score

with pytest.raises(ValueError):
data_ce = vector_store_cloud.search(
vector_store_cloud.search(
query=f"SELECT * WHERE id=='{vector_store_cloud.dataset.id[0].numpy()[0]}'",
embedding=query_embedding,
k=2,
Expand Down Expand Up @@ -514,7 +514,7 @@ def test_search_quantitative(distance_metric, hub_cloud_dev_token):

with pytest.raises(ValueError):
# use indra implementation to search the data
data_ce = vector_store.search(
vector_store.search(
query="select * where metadata == {'abcdefg': 28}",
exec_option="compute_engine",
distance_metric=distance_metric,
Expand Down
8 changes: 4 additions & 4 deletions deeplake/core/vectorstore/vector_search/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ def get_not_none_tensors(tensors, embedding_data):

def populate_id_tensor_if_needed(ids_tensor, tensors, not_none_tensors, num_items):
if "id" not in not_none_tensors and "ids" not in not_none_tensors:
id = [str(uuid.uuid1()) for _ in range(num_items)]
tensors[ids_tensor] = id
found_id = [str(uuid.uuid1()) for _ in range(num_items)]
tensors[ids_tensor] = found_id
else:
for tensor in not_none_tensors:
if tensor in ("id", "ids"):
Expand Down Expand Up @@ -364,14 +364,14 @@ def update_embedding_info(logger, dataset, embedding_function):

if num_embedding_tensors == 0:
logger.warning(
f"No embedding tensors were found, so the embedding function metadata will not be added to any tensor. "
"No embedding tensors were found, so the embedding function metadata will not be added to any tensor. "
"Consider doing that manually using `vector_store.dataset.tensor_name.info. = <embedding_function_info_dictionary>`"
)
return
if num_embedding_tensors > 1:
logger.warning(
f"{num_embedding_tensors} embedding tensors were found. "
f"It is not clear to which tensor the embedding function information should be added, so the embedding function metadata will not be added to any tensor. "
"It is not clear to which tensor the embedding function information should be added, so the embedding function metadata will not be added to any tensor. "
"Consider doing that manually using `vector_store.dataset.tensor_name.info = <embedding_function_info_dictionary>`"
)
return
Expand Down
10 changes: 5 additions & 5 deletions deeplake/core/vectorstore/vector_search/dataset/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_create(caplog, hub_cloud_path, hub_cloud_dev_token):

# Test whether not specifiying runtime with exec_option tensor_db raises error
with pytest.raises(ValueError):
dataset = dataset_utils.create_or_load_dataset(
dataset_utils.create_or_load_dataset(
tensor_params=DEFAULT_VECTORSTORE_TENSORS,
dataset_path="hub://testingacc2/vectorstore_test_create_dbengine",
token=hub_cloud_dev_token,
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_load(caplog, hub_cloud_dev_token):
test_logger = logging.getLogger("test_logger")
with caplog.at_level(logging.WARNING, logger="test_logger"):
# dataset loading
dataset = dataset_utils.create_or_load_dataset(
dataset_utils.create_or_load_dataset(
tensor_params=DEFAULT_VECTORSTORE_TENSORS,
dataset_path=DEFAULT_VECTORSTORE_DEEPLAKE_PATH,
token=None,
Expand All @@ -142,7 +142,7 @@ def test_load(caplog, hub_cloud_dev_token):
)

with pytest.raises(ValueError):
dataset = dataset_utils.create_or_load_dataset(
dataset_utils.create_or_load_dataset(
tensor_params={"name": "image", "htype": "image"},
dataset_path=DEFAULT_VECTORSTORE_DEEPLAKE_PATH,
token=None,
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_delete_and_commit():
dataset.ids.extend([1, 2, 3, 4, 5, 6, 7, 8, 9])

dataset_utils.delete_and_commit(dataset, ids=[1, 2, 3])
len(dataset) == 6
assert len(dataset) == 6


def test_delete_all():
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_fetch_embeddings():
def test_embeding_data():
query = "tql query"
with pytest.raises(Exception):
embedding = dataset_utils.get_embedding(
dataset_utils.get_embedding(
embedding=None, query=query, embedding_function=None
)

Expand Down
6 changes: 3 additions & 3 deletions deeplake/core/vectorstore/vector_search/indra/query.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import numpy as np

from typing import List
from typing import List, Optional

from deeplake.core.vectorstore.vector_search.indra import tql_distance_metrics


def create_query_string(
distance_metric: str,
distance_metric: Optional[str],
tql_filter: str,
limit: int,
order: str,
order: Optional[str],
tensor_list: List[str],
):
"""Function for creating a query string from a distance metric, limit and order.
Expand Down
2 changes: 1 addition & 1 deletion deeplake/enterprise/test_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def test_indexes_tensors(hub_cloud_ds, num_workers):
ds.xyz.append(i * np.ones((2, 2)))

with pytest.raises(ValueError):
ptds = (
(
hub_cloud_ds.dataloader()
.batch(4)
.tensorflow(
Expand Down
2 changes: 1 addition & 1 deletion deeplake/util/connect_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def is_path_connectable(path: str, allow_local: bool) -> bool:

def connect_dataset_entry(
src_path: str,
creds_key: str,
creds_key: Optional[str],
dest_path: Optional[str] = None,
org_id: Optional[str] = None,
ds_name: Optional[str] = None,
Expand Down
4 changes: 2 additions & 2 deletions deeplake/visualizer/tests/test_playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_linked_video_playback(local_ds_generator, gcs_path):
ds.populate_creds("ENV", from_environment=True)
ds.video_links.append(
deeplake.link(
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4",
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4",
creds_key="ENV",
)
)
Expand All @@ -49,7 +49,7 @@ def test_linked_video_playback(local_ds_generator, gcs_path):
url = ds.video_links[0]._get_video_stream_url()
assert (
url
== "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"
== "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"
)
http_data = urlopen(url).read()

Expand Down

0 comments on commit aac3873

Please sign in to comment.