From f1bc60aa1e0fea64b4fa4929f224e1fcc17b0d29 Mon Sep 17 00:00:00 2001 From: Rehan Durrani Date: Thu, 2 Jun 2022 19:17:28 -0700 Subject: [PATCH] Add support for windows Signed-off-by: Rehan Durrani --- modin/core/io/utils.py | 8 ++++++-- modin/pandas/test/test_io.py | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modin/core/io/utils.py b/modin/core/io/utils.py index 56cc7f487b2..1fd171970bd 100644 --- a/modin/core/io/utils.py +++ b/modin/core/io/utils.py @@ -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: @@ -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 diff --git a/modin/pandas/test/test_io.py b/modin/pandas/test/test_io.py index 69d2cba3a0a..ac9b522e630 100644 --- a/modin/pandas/test/test_io.py +++ b/modin/pandas/test/test_io.py @@ -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!"