Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/test_init.py
6939 views
1
import importlib
2
3
import pytest
4
5
import polars as pl
6
from polars.exceptions import ComputeError
7
8
9
def test_init_nonexistent_attribute() -> None:
10
with pytest.raises(
11
AttributeError, match="module 'polars' has no attribute 'stroopwafel'"
12
):
13
pl.stroopwafel # type: ignore[attr-defined]
14
15
16
def test_init_exceptions_deprecated() -> None:
17
with pytest.deprecated_call(
18
match="accessing `ComputeError` from the top-level `polars` module was deprecated in version 1.0.0."
19
):
20
exc = pl.ComputeError # type: ignore[attr-defined]
21
22
msg = "nope"
23
with pytest.raises(ComputeError, match=msg):
24
raise exc(msg)
25
26
27
def test_dtype_groups_deprecated() -> None:
28
with pytest.deprecated_call(
29
match="`INTEGER_DTYPES` was deprecated in version 1.0.0."
30
):
31
dtypes = pl.INTEGER_DTYPES # type: ignore[attr-defined]
32
33
assert pl.Int8 in dtypes
34
35
36
def test_type_aliases_deprecated() -> None:
37
with pytest.deprecated_call(
38
match="the `polars.type_aliases` module was deprecated in version 1.0.0."
39
):
40
from polars.type_aliases import PolarsDataType
41
assert str(PolarsDataType).startswith("typing.Union")
42
43
44
def test_import_all() -> None:
45
exec("from polars import *")
46
47
48
def test_version() -> None:
49
# This has already gone wrong once (#23940), preventing future problems.
50
assert (lhs := pl.__version__) == (rhs := importlib.metadata.version("polars")), (
51
f"`static PYPOLARS_VERSION` ({lhs}) at `crates/polars-python/src/c_api/mod.rs` "
52
f"does not match importlib package metadata version ({rhs})"
53
)
54
55