From 4414a4c067f740a7ff2327ab80880db35253f36b Mon Sep 17 00:00:00 2001 From: Douglas Myers-Turnbull Date: Fri, 5 Nov 2021 10:51:54 -0700 Subject: [PATCH] fix: url error on windows --- tests/test_fancy_io.py | 2 +- typeddfs/_mixins/_full_io_mixin.py | 2 +- typeddfs/abs_dfs.py | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_fancy_io.py b/tests/test_fancy_io.py index f21839d..2379e36 100644 --- a/tests/test_fancy_io.py +++ b/tests/test_fancy_io.py @@ -336,7 +336,7 @@ def test_read_write_insecure(self): bad_type = TypedDfBuilder("a").recommended_only().build() with pytest.raises(UnsupportedOperationError): # noinspection HttpUrlsUsage - secure_type.read_file("http://google.com") # nosec + secure_type.read_url("http://google.com") # nosec secure = secure_type.new_df() bad = bad_type.new_df() for fmt in FileFormat: diff --git a/typeddfs/_mixins/_full_io_mixin.py b/typeddfs/_mixins/_full_io_mixin.py index 0a5228f..148b73e 100644 --- a/typeddfs/_mixins/_full_io_mixin.py +++ b/typeddfs/_mixins/_full_io_mixin.py @@ -55,7 +55,7 @@ def _call_read( ) -> pd.DataFrame: fmt = cls._get_fmt(path) # noinspection HttpUrlsUsage - if isinstance(path, str) and path.startswith("http://"): + if str(path).startswith("http://"): raise UnsupportedOperationError("Cannot read from http with .secure() enabled") cls._check_io_ok(path, fmt) kwargs = cls._get_read_kwargs(fmt, path) diff --git a/typeddfs/abs_dfs.py b/typeddfs/abs_dfs.py index 3ac939f..61526e1 100644 --- a/typeddfs/abs_dfs.py +++ b/typeddfs/abs_dfs.py @@ -94,6 +94,9 @@ def read_file( Returns: An instance of this class """ + if any((str(path).startswith(x + "://") for x in ["http", "https", "ftp"])): + # just save some pain -- better than a weird error in .resolve() + raise ValueError(f"Cannot read from URL {path}; use read_url instead") path = Path(path).resolve() t: DfTyping = cls.get_typing() if attrs is None: @@ -166,6 +169,9 @@ def write_file( InvalidDfError: If the DataFrame is not valid for this type ValueError: If the type of a column or index name is non-str """ + if any((str(path).startswith(x + "://") for x in ["http", "https", "ftp"])): + # just save some pain -- better than a weird error in .resolve() + raise ValueError(f"Cannot write to URL {path}") path = Path(path).resolve() t = self.__class__.get_typing() file_hash = file_hash is True or file_hash is None and t.io.file_hash