Skip to content
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

feat(python): allow ftp URLs, improve URL check #13781

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jan 17, 2024

We had a very basic check against string file paths to see if they looked like they might be a URL (just "starts with http"). This can lead to (somewhat unlikely) false positives against files in the local working dir, fail on upper/mixed case URL prefixes, and excludes the ftp protocol, which the underlying urlopen method does actually handle.

Made the check more robust, and added some related unit tests.
Validated by loading CSV data off an ftp server; worked fine👌

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Jan 17, 2024
Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@@ -222,7 +222,11 @@ def _check_empty(
return b


def _process_http_file(path: str, encoding: str | None = None) -> BytesIO:
def _looks_like_url(path: str) -> bool:
return re.match("^(ht|f)tps?://", path, re.IGNORECASE) is not None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today I learned about the FTPS protocol 😄

@stinodego stinodego merged commit f9ba80c into pola-rs:main Jan 18, 2024
22 checks passed
@alexander-beedie alexander-beedie deleted the support-ftp-reads branch January 18, 2024 09:40
r-brink pushed a commit to r-brink/polars that referenced this pull request Jan 22, 2024
r-brink pushed a commit to r-brink/polars that referenced this pull request Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants