- 
                Notifications
    
You must be signed in to change notification settings  - Fork 669
 
FIX-#4479: Prevent users from using a local filepath when performing a distributed write #4484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
aca8db5
              e622fcf
              be74c8e
              7b1dff6
              a313a79
              1dd8636
              4191088
              8c7120b
              dcadcf4
              b6552ba
              0608f9e
              cc80818
              8081d9c
              9c108af
              f1bc60a
              a7acd81
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Licensed to Modin Development Team under one or more contributor license agreements. | ||
| # See the NOTICE file distributed with this work for additional information regarding | ||
| # copyright ownership. The Modin Development Team licenses this file to you under the | ||
| # Apache License, Version 2.0 (the "License"); you may not use this file except in | ||
| # compliance with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software distributed under | ||
| # the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
| # ANY KIND, either express or implied. See the License for the specific language | ||
| # governing permissions and limitations under the License. | ||
| 
     | 
||
| """Collection of utility functions for distributed io.""" | ||
                
      
                  RehanSD marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| import os | ||
| import pathlib | ||
| import re | ||
| 
     | 
||
| S3_ADDRESS_REGEX = re.compile("[sS]3://(.*?)/(.*)") | ||
| 
     | 
||
| 
     | 
||
| def is_local_path(path_or_buf) -> bool: | ||
| """ | ||
| Return True if the specified path_or_buf is a local path, False otherwise. | ||
                
      
                  RehanSD marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| Parameters | ||
| ---------- | ||
| path_or_buf : str, path object or file-like object | ||
| The path or buffer to check. | ||
| Returns | ||
| ------- | ||
| Whether the `path_or_buf` points to a local file. | ||
| """ | ||
| if isinstance(path_or_buf, str): | ||
| if S3_ADDRESS_REGEX.match(path_or_buf) is not None or "://" in path_or_buf: | ||
| return False # S3 or network path. | ||
| if isinstance(path_or_buf, str) or isinstance(path_or_buf, pathlib.PurePath): | ||
                
      
                  RehanSD marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| return os.path.exists(path_or_buf) | ||
                
       | 
||
| return False | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be moved to
_to_csv_check_support, ditto for parquet?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but
_to_csv_check_supportcurrently just checks if we can do a parallel write, so it would be a bit of a paradigm shift to raise an error here, unless you're suggesting we return false and default to a serial write on the head node if a local path is passed?