Skip to content

Commit

Permalink
Add support for windows
Browse files Browse the repository at this point in the history
Signed-off-by: Rehan Durrani <[email protected]>
  • Loading branch information
RehanSD committed Jun 3, 2022
1 parent 9c108af commit f1bc60a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions modin/core/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import re
import fsspec

IS_FILE_ONLY_REGEX = re.compile("[^\/]*\.\w+") # noqa: W605
IS_FILE_ONLY_REGEX = re.compile(f"[^\\{os.sep}]*\.\w+") # noqa: W605


def is_local_path(path) -> bool:
Expand Down Expand Up @@ -45,13 +45,17 @@ def is_local_path(path) -> bool:
parent_dir = os.getcwd()
else:
# If we are passed a full path, we want to remove the filename from it.
parent_dir = "/".join(path.split("/")[:-1])
parent_dir = os.sep.join(path.split(os.sep)[:-1])
fs = fsspec.core.url_to_fs(parent_dir)[0] # Grab just the FileSystem object
if hasattr(
fs, "local_file"
): # If the FS does not have the `local_file` attr, it is not local.
# We still need to check that it is not a mounted file - as fsspec treats mounted
# files the same as local ones, but we want to distinguish between local and mounted.
if os.name == "nt" and parent_dir[:3] == "D:\\":
# In Windows, os.path.abspath(os.sep) will give us the C Drive, but we want the
# D drive to also be marked as local.
return True
local_device_id = os.stat(os.path.abspath(os.sep)).st_dev
path_device_id = os.stat(parent_dir).st_dev
return path_device_id == local_device_id
Expand Down
6 changes: 5 additions & 1 deletion modin/pandas/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,11 @@ def test_is_local_path():
assert is_local_path(
os.getcwd()
), "Current Working Directory incorrectly flagged as not local!"
new_file = os.getcwd() + "/modin-example-file"
new_file = os.getcwd() + "/modin-example-file.extension"
assert is_local_path(
new_file
), "Non-existent file under current working directory incorrectly flagged as not local!"
new_file_in_curr_dir = "modin-example-file.extension"
assert is_local_path(
new_file_in_curr_dir,
), "Non-existent file without absolute path incorrectly flagged as not local!"

0 comments on commit f1bc60a

Please sign in to comment.