Paths joined as strings
See original GitHub issueLooking through the code surrounding dataset downloads, I noticed that in get_local_storage_path
two path-representing strings are joined via an f string:
Are there reasons why these are not Path
s? I would have expected the following:
from pathlib import Path
def get_local_storage_path(path: str, prefix: Path) -> Path:
local_cache_name = path.replace("://", "_")
local_cache_name = local_cache_name.replace("/", "_")
local_cache_name = local_cache_name.replace("\\", "_")
return prefix / local_cache_name
Or at least:
import os
def get_local_storage_path(path: str, prefix: str) -> str:
local_cache_name = path.replace("://", "_")
local_cache_name = local_cache_name.replace("/", "_")
local_cache_name = local_cache_name.replace("\\", "_")
return os.path.join(prefix, local_cache_name)
By the way, I noticed this because I got a string/path with two slashes (//
) from get_local_dataset
:
deeplake.util.exceptions.DatasetHandlerError: A dataset does not exist at the download location /tmp/deeplake//hub_activeloop_fashionpedia-train. Cannot use access method 'local'. Use access method 'download' to first download the dataset and then use access method 'local' in subsequent runs.
Issue Analytics
- State:
- Created a year ago
- Comments:8
Top Results From Across the Web
Path.Join Method (System.IO) - Microsoft Learn
The Join method concatenates the two strings and preserves duplicate path separators. The Combine method abandons the drive and returns a rooted directory...
Read more >Python | os.path.join() method - GeeksforGeeks
This method concatenates various path components with exactly one directory separator ('/') following each non-empty part except the last path ...
Read more >python - Platform independent path concatenation using "/" , "\"?
You want to use os.path.join() for this. The strength of using this rather than string concatenation etc is that it is aware of...
Read more >Python | Join List as Path - Finxter
Create a string by joining all path components using the os.path.join(…) method. You unpack all strings in the list using the asterisk operator....
Read more >Mistakes I've made treating file paths as strings - Phil Nash
So you can treat them like strings, joining them or concatenating them until you pass ... Use path.join whenever you have to join...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jangop Hey there, thanks for raising the issue. There’s no reason for joining the paths as strings and we should do it the way you suggested.
Yep, there is no need to switch in this case with the new implementation. Just use
access_method="local"
. Only ever need to useaccess_method="download"
for re-downloading the dataset.Oops, that’s a mistake in the docs, thanks for pointing it out.