Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/io/cloud/test_cloud.py
6939 views
1
from __future__ import annotations
2
3
import contextlib
4
from functools import partial
5
6
import pytest
7
8
import polars as pl
9
10
11
@pytest.mark.slow
12
@pytest.mark.parametrize("format", ["parquet", "csv", "ndjson", "ipc"])
13
def test_scan_nonexistent_cloud_path_17444(format: str) -> None:
14
# https://github.com/pola-rs/polars/issues/17444
15
16
path_str = f"s3://my-nonexistent-bucket/data.{format}"
17
scan_function = getattr(pl, f"scan_{format}")
18
# Prevent automatic credential provideder instantiation, otherwise CI may fail with
19
# * pytest.PytestUnraisableExceptionWarning:
20
# * Exception ignored:
21
# * ResourceWarning: unclosed socket
22
scan_function = partial(scan_function, credential_provider=None)
23
24
# Just calling the scan function should not raise any errors
25
if format == "ndjson":
26
# NDJSON does not have a `retries` parameter yet - so use the default
27
result = scan_function(path_str)
28
else:
29
result = scan_function(path_str, retries=0)
30
assert isinstance(result, pl.LazyFrame)
31
32
# Upon collection, it should fail
33
with pytest.raises(IOError):
34
result.collect()
35
36
37
def test_scan_err_rebuild_store_19933() -> None:
38
call_count = 0
39
40
def f() -> None:
41
nonlocal call_count
42
call_count += 1
43
raise AssertionError
44
45
q = pl.scan_parquet(
46
"s3://.../...",
47
storage_options={"aws_region": "eu-west-1"},
48
credential_provider=f, # type: ignore[arg-type]
49
)
50
51
with contextlib.suppress(Exception):
52
q.collect()
53
54
# Note: We get called 2 times per attempt
55
if call_count != 4:
56
raise AssertionError(call_count)
57
58